0

I need to create a dynamic link to take the user to the last page of the laravel page. For example, if there is a pagination, I need to include lastPage () at the end of the url www.site.com/forum/slug?page=2

otherwise it goes to the normal page.

But I need to do this logic on another controller, which in turn is not working. See my relationships and how I'm doing:

public function grupoPerfil($slug) {


        $grupo = Grupo::where('slug', $slug)->first();

        $comments = Comment::whereHas('relato', function ($query) use ($grupo) {
            return $query->where('grupo_id', $grupo->id);
        })->paginate(10);


        if($grupo){

            $rels = $grupo->relatos()->with('user')->paginate(20);
            
            return view('grupo', compact(['grupo', 'rels','comments']));
            
        }

        abort(404);    
        
    }

my blade:

@foreach($rels->sortByDesc('updated_at') as $r)

                <card-relatos 
                url="{{localized_route('relatoUser', [$r->grupo->slug, $r->slug])}}"
                getpaginate="{{ $comments->lastPage() }}"
                </card-relatos>

 @endforeach

But getpaginate always returns 2, as it is not related to relato_id. How do I solve this?

  • Problem is that you are using tvo paginations on one page. In this case you have to set get parameter for second pagination. More here: https://stackoverflow.com/questions/24086269/laravel-multiple-pagination-in-one-page – Autista_z Sep 03 '20 at 20:47

1 Answers1

0

This is what I have done:

return Product::whereHas('category', function ($query) use ($slug) {
        $query->where('slug', $slug);
    })->paginate(15);