Reputation: 1
I have selected data from two models by with() method and now I want to display these Two models' record in view, how can I do this.
$posts=Post::where('slug','=',Str::lower($id))->with('comment')->first();
Upvotes: 0
Views: 75
Reputation: 310
In your controller use this
$posts=Post::where('slug','=',Str::lower($id))->get();
return view('view.name',compact('posts');
Lets try this in your blade
@foreach($posts as $val)
{{$val->comment()->id}}
@endforeach
Upvotes: 1
Reputation: 177
In controller
return view('view.name', ['posts' => $posts]);
In view
@foreach($posts as $post)
//do something
@endforeach
Upvotes: 0