0
votes

Pagination works fine when i search for hotels pages, but when i select to view an hotel with it propre rooms , i get the hotel but the rooms aren't paginated like i got 3 rooms instead of 100{paginated} also no page numbers

What i m doing wrong

the code from controller::

{
        $hotel = Hotel::where('slug', $slug)->first();  
        $hotel_id = $hotel->id;     
        $rooms = Room::where('hotel_id', $hotel_id)->paginate(3);
        return view('hotels.show',['hotel' => $hotel, 'rooms' => $rooms ]);
}

the blade html:

<div> {{ $hotel->title }} </div>

@foreach($rooms as $room)
<div>Room: {{ $room->title }} </div>
@endforeach
1

1 Answers

4
votes

paginate (3) means its give you 3 room in every page.. if you want to paginate 100 in every page then you should use paginate (100) instead of 3.

And if you want to show the links/pages then just simply call $rooms->links()

Your code looks like:-

<div> {{ $hotel->title }} </div>

@foreach($rooms as $room)
<div>Room: {{ $room->title }} </div>
@endforeach

<div> {{ $rooms->links() }} </div>