How to join tables in laravel Eloquent
Join multiple tables using Laravel Eloquent
join two tables
in this example we will retrieve the data from Post and Comments tables
$users = Post::join('comments', 'post.id', '=', 'comments.post_id')->get(['posts.*', 'comments.message']);
Join three tables
in this example we will retrieve the data from Users and Post and Comments tables
$users = Users::join('posts', 'post.id', '=', 'user.post_id')->join('posts', 'post.id', '=', 'user.post_id')
->get(['posts.*', 'comments.message']);
->get(['posts.*', 'comments.message']);
Comments
Post a Comment