Jake2315's avatar

How would I pass pagination to my show method in this situation?

I basically have these thumbnails. Each thumbnail literally 'hasMany country'. I know I'm not passing the pagination to the show action method, but I also don't have a clue how I would go with this either (since I'm using Route Model Binding).

My web.php:

Route::get("/{thumbnail}/countries", 'CountryController@show');

My CountryController:

public function show(Thumbnail $thumbnail)
{
    return view('country.show', [
        'thumbnail' => $thumbnail
    ]);
}

My country/show.blade.php:

        @foreach ($thumbnail->countries as $country)
            <div class="col-md-4" style="margin-top: 15px;">
                <div class="thumbnail">
                    <img src="{{ url('images/welcome/' . $country->media) }}">
                    <div class="caption">
                        <span style="font-size: 40px;">{{ $country->artist }}.</span>
                        <button style="margin-top: 16px;" class="btn btn-primary pull-right">Add To Shopping Cart &nbsp;<i class="fa fa-cart-plus" aria-hidden="true"></i></button>
                    </div>                  
                </div>  
            </div>
        @endforeach

        {{ $thumbnail->countries->links() }}

Thanks in advance.

0 likes
1 reply
Organizm238's avatar
Level 8

Just pass it as separate paginated collection:

public function show(Thumbnail $thumbnail)
{
    
    $countries = $thumbnail->countries()->paginate(10);
    return view('country.show', [
        'thumbnail' => $thumbnail,
        'countries' => $countries,
    ]);
}

Then in your view loop over $countries variable:


 @foreach ($countries as $country)
...
@endforeach 

{{ $countries->links() }}
2 likes

Please or to participate in this conversation.