How to use inner join in Laravel 5?

1

I have the following loop in a view table

@foreach ($filme as $f)
    <tr>
        <td>{{ $f->fil_id }}</td>
        <td>{{ $f->fil_filme }}</td>
        <td>{{ $f->fil_sinopse }}</td>
        <td>{{ $f->fil_lancamento }}</td>        
        <td>{{ $f->cat_id }}</td>
    </tr>
@endforeach

But it only displays the category id because it is in the movie table. How to give an INNER JOIN with the category table in laravel 5?

    
asked by anonymous 11.12.2017 / 03:20

1 answer

1

You can use Query Builder to do joins

To perform a basic "join", you can use the method in an instance of the query builder. The first argument passed to the join method is the name of the table to which you need to join, while the remaining arguments specify the column constraints for the join. Of course, as you can see, you can join multiple tables in a single query:

$users = DB::table('users')
            ->join('contacts', 'users.id', '=', 'contacts.user_id')
            ->join('orders', 'users.id', '=', 'orders.user_id')
            ->select('users.*', 'contacts.phone', 'orders.price')
            ->get();
  

LARAVEL - Database: Query Builder

    
11.12.2017 / 03:31