Laravel PHP Join 2 Tables with Example

In laravel we can join 2 or multiple tables in side code.

Using below code you can join 2 tables, There we trying to join User table with Post table.

$users = User::join('Post', 'User.id', '=', 'Post.user_id')
               ->get(['User.*', 'Post.details']);

Join to multiple tables

$users = User::join('Post', 'Post.user_id', '=', 'User.id')
            ->where('User.status', 'active')
            ->where('Post.status','active')
            ->get(['User.*', 'Post.details']);