jofred's avatar

Paginate

I have a query that returns 51 rows, in a view i'm using pagination, if i use ->paginate(1) in the query the pagination doesn't work, it always shows the value of the first row in all 51 pages, if i change the pagination to more than one (->paginate(2)) it works. Anyone knows how to fix this? Thanks!

0 likes
7 replies
jdunsmore's avatar

The number you put in the brackets is the number of items per page.

You should be seeing different results per page.

Can you show us your controller and view code.

jofred's avatar

Controller:

public function index(Request $request) {

     $placue = sifplanunicta::
        select('spu_id_cod','spu_ano_fiscal','spu_descripcion','spu_tipo_cta','spu_tipo_movi')
        ->Codigo($request->buscod)
        ->Anno($request->busanof)
        ->Descrip($request->busdes)
        ->orderBy('spu_ano_fiscal')
        ->paginate(1);
        
        return view('plancuentas.vercuentas',['plancuen'=>$placue]);  
}

/***************************************************************************************************************/

View:

            @foreach ($plancuen as $placue)

                <tr>

                    <td>{{ $placue->spu_id_cod }}</td>

                    <td>{{ $placue->spu_ano_fiscal }}</td>

                    <td>{{ substr($placue->spu_descripcion,0,87) }}</td>

                    <td class="text-center" >
                        {{ $placue->spu_tipo_cta == 'D' ? 'Deudora' : 'Acreedora' }}
                    </td>

                    <td class="text-center" >
                        {{ $placue->spu_tipo_movi == 'M' ? 'Movimiento' : 'Total' }}
                    </td>

            @endforeach 

     <div class="text-center">

    {{ $plancuen->appends(Request::only(['buscod','busanof','busdes']))->links() }}

</div>
jdunsmore's avatar

A little difficult to understand as you speak Spanish I think..

Example pagination (from docs)

Controller

$users = DB::table('users')->paginate(15);

return view('user.index', ['users' => $users]);

View

<div class="container">
    @foreach ($users as $user)
        {{ $user->name }}
    @endforeach
</div>

{{ $users->appends(['sort' => 'votes'])->links() }}
jofred's avatar

@jdunsmore can you try in some app where you have pagination with paginate(1) and then check if the pagination in the view is working ok ?

Ex:

$users = DB::table('users')->paginate(1);

return view('user.index', ['users' => $users]);

Thanks!

@Snapey

Yes it is!

jdunsmore's avatar

@jofred

I have previously tested what you are looking for - the pagination functions as expected. I do it for everything as most test data I input isn't near the length of the actual pagination the app would use.

Please or to participate in this conversation.