Categories: php, laravel, eloquent

Laravel 5.7 pagination not working after first page result

1 answer

I intend to paginate a laravel eloquent model using a where clause. I expect the page links to show and be clickable leading to the clicked page. This is the default controller in which I paginate without a where clause.

 public function index(Request $request){    $users = User::paginate(12)->onEachSide(1);              return view('/**',compact('users')); } 

I am able to paginate through till the last page. This is the route (I have placed the name is asterisks for confidentiality.:

Route::get('/**', 'SearchController@index'); 

This functions better, however I try to limit the rows with a where clause:

  public function search(Request $request){  $location = $request->location; $talent  = $request ->talent;  $users = User::where('talent',$talent)->where('location',$location)->paginate(12);  return view('/searchResult',compact('users');       } 

This is the route:

Route::get('/**', 'SearchController@search'); 

However, in the second case, the pagination result returns blank when I try to navigate. I am not sure why this is happening. On the front view, I have:

              {{$users->links()}} 

All answers to this question, which has the identifier 61217466

The best answer:

This code works and I am now able to paginate effectively. Answer by lufc in the comment though. However, I am curious about the mechanism.

     {{ $users->appends(Request::except('page'))->links() }} 

Last questions

how do i remove the switch on my home screen?
how to edit the JS date and time to update atuomatically?
How to utilize data stored in a multidimensional array
Powermockito not mocking URL constructor in URI.toURL() method
Android Bluetooth LE Scanner only scans when phone's Location is turned on in some devices
docker wordpress container can't connect to mysql container
How can I declare a number in java that is more than 64-bits? [duplicate]
Optaplanner solutionClass entityCollectionProperty should never return null error when simple JSON object passed to controller
Anylogic, get the time a pedestrain is in a queue
How do I fix this syntax issue with my .flex file?
Optimizing query in PHP
How to find the highest number of a column and print two columns of that row in R?
Ideas on “Error: Type com.google.firebase.iid.zzav is referenced as an interface from com.google.firebase.messaging.zzd”?
JCIFS SmbFile.exists() and SmbFile.isDirectory() return false when it exists and I can listFiles()
PHP total order
Laravel booking system design
neural net - undefined column selected
How to indicate y axis does not start from 0 in ggplot?
Fragments in backStack
Spinner how to change the data