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