Wednesday 13 July 2016

How to solve Call to undefined method Illuminate\Database\Query\Builder::links()


When building pagination in laravel it is more likely to come across this error call to undefined method. This happen when trying to get other record in the variable.

This problem is cause when a variable that was passed from controller or route is re-generated by foreach statement. To avoid this error, make sure the re-generated variable name by foreach statement is different from the original variable.

And when using the links(), used it with the original variable not the re-generated variable by the foreach statement. For instance,

Assuming $record is our original variable,

@foreach($record as records) // when trying to get other records in the variable.

//display the records

@endforeach

<div class="pagination">{!!$record->links()!!}</div> // display pagination

Take note that this variable “$record”  is different from “$records”. The first is the original variable while the latter is the regenerated variable and we used the original for the pagination

3 comments:

  1. You are a 'A pagination'

    It works

    ReplyDelete
  2. woow thanks a million time u just save a soul after 2 days of searching

    ReplyDelete
  3. Muchas gracias!!! me ayudó mucho tu respuesta!!!

    ReplyDelete