$hotels = Hotel::where('id', '=', $hotel[0]->hotel_id)->paginate(10);
So I will get one hotel for $hotel[0]->hotel_id . And if I need to get 10 hotels for example for different $hotel[10]->hotel_id .
Need to write something like that?

 $id = Auth::user()->id; $hotel = UserHotel::where('user_id', '=', $id)->get(); for($i = 0; $i < count($hotel); $i++){ $hotel[] = Hotel::where('id', '=', $hotel[$i]->hotel_id)->paginate(10); } 

  • whereIn ('id', [array_id_hotels]) - Orange_shadow

1 answer 1

It would be easier to do this:

 $id = Auth::user()->id; $userHotelIds = UserHotel::where('user_id', $id)->get()->pluck('hotel_id'); $hotel = Hotel::whereIn('id', $userHotelIds)->paginate(10); 

But in fact, it would be even easier to do this through the reports, would suggest knowing your database structure.

  • Thanks It works. But I didn’t quite understand how) because in the view in $hotel see only 1 entry, but it displays everything. - Andrii
  • In the same place the paginator should be, and in it the iterator, in due course you will understand =) - Yaroslav Molchan