mardi 29 août 2017

laravel eloquent nested SELECT statement

I am using LARAVEL with eloquent with MYSql I have three tables POSTS USERS and COMMENTS. My POST and COMMENT are in One-to-many relation thus with the following code I get the list of Comments for particular POST id

   $post =  Post::where('id', $id)->get();
   $comment = Post::find($id)->comment()->paginate(10);       
   return view('posts\single', ['post' => $post, 'comments' => $comment]);

Now I want to get the Details of each user from the USER table. I dont want to use the foreach() and then get details of every single ID. Is there any method by which I can get all the Comments(From COMMENTS table) including user details (From USER table) at a single call.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire