3 months ago

Link on another page to last pagination URL [ SOLVED ]

Posted 3 months ago by mvnobrega

I am working on a project similar to a discussion forum. I need to create a link that takes the user to the last URL paginate.

My group controller :

public function gruposIndex (Request $ request) {

     $ groups = Group :: paginate (9);

         return view ('dreams', compact ('groups'));

My groups view:

@foreach($grupos as $g)     
                    <div class="testimonial">
                        <div class="meta">

                            <div class="avatar has-photo"><img src="{{Storage::url($g->foto)}}"></div>
                    <div class="meta-perfil-relatos">
                        <div><span class="fas fa-calendar-alt"></span>0</div>
                        <div><span class="fas fa-thumbs-up"></span>0</div>
                        <div><span class="fas fa-comments"></span>85</div>
                         <div class="author">

                        <div class="btn-sonhos">
                            <a href="{{ route('grupoPerfil', $g->slug)}}" class="btn btn-action">Entrar<span class="far fa-arrow-right"></span></a>

When the user clicks the link: {{ route('grupoPerfil', $g->slug)}} I need it to be taken to the last pagination link, for example

Which in the controller looks like this:

public function grupoPerfil($slug) {

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

        $rels = $grupo->relatos()->paginate(10);

            return view('perfilGrupo', compact(['grupo', 'rels']));


And view:

 @foreach($rels->sortBy('created_at') as $r)
            <div class="thread ">
                <div class="main-info">
                    <div class="avatar"><img src="{{$r->user->avatar}}" title="Posted by Stephen"></div>
                    <div class="name">
                        <div class="title"><a href="{{ route('relatoUser', [$r->grupo->slug, $r->slug] ) }}">{{$r->titulo}}</a></div>
                        <div class="excerpt">
                            {{str_limit($r->relato, 60)}}
                <div class="meta">
                    <div class="answer-count"><span class="far fa-comment"></span> <span class="simple-text">{{$r->comments->count()}}</span> 
                        <span class="nice-text">{{$r->comments->count()}} respostas</span>
                    <div class="date">
                        <div class="poster">
                        <div class="diff">em {{$r->created_at->format('d/m/Y')}}</div>
            {{ $rels->links() }}

Need this solution because the last page of {{ $rels->links() }} will be the most recent

I am having trouble finding a solution to this. Can someone help me?

Please sign in or create an account to participate in this conversation.