I have 2 tables: t1: hotels t2: people
There are 5 hotels and in every hotel a different number of people. I'd like to get hotel name and people's names assigned to that hotel. With the query I have it duplicated the hotel name as many times as there are people in it.
$hotels=DB::table('hotels')
->select('hotels.*','people.name')
->leftjoin('people','people.hotel_id','=','hotel.id')
->get();
return view('hotels', ['hotels' => $hotels]);
And in my view I have
@foreach($hotels as $h)
$h->hotel_name
@endforeach
hotel_name now shows up 4 times which is the same number of people assigned to the hotel_id. I've tried using group_concat but with that I could only get the names of the people.
Is there a group by or some other method which could help me to get to my goal?