Get join values Laravel

According documentation about joins:

https://laravel.com/docs/8.x/queries#joins

As example:

$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();

OK, I have my values into $users. If I do, with blade:

{{ $users }}

I can see this result, in JSON format. But, How can I get each single value, using Blade? (Ex: contacts.phone, or orders.price, in this example)

Thanks on advance

1 answer

  • answered 2021-04-14 22:25 kemp

    @foreach($users as $user)
        {{ $user }}
    @endforeach
    

    You can substitute $user with any variable you wish.

    Docs: Laravel