I have a problems on the pagination spesificly when try to searching data by some condition its work properly, But when i try to change the page the data wont sort by the condition.the the search work properly but it gone wrong when i change the page.
this is my code
public function fotoTrxSearch(Request $request){
$transaction = Foto::OrderByDesc('id');
if($request->filled('name')){
$transaction->where('name', 'like', "%{$request->name}%")->orderBy( 'id', 'desc');
}
if($request->filled('from') AND $request->filled('to')){
$transaction->whereBetween('date', [$request->get('from'), $request->get('to')])->orderBy( 'id', 'desc');
}
if($request->filled('price')){
$transaction->where('price','like', "%{$request->price}%")->orderBy( 'id', 'desc');
}
if($request->filled('folder')){
$transaction->where('folder','like', "%{$request->folder}%")->orderBy( 'id', 'desc');
}
$transaction = new FotoCollection($transaction->paginate(150));
return Inertia::render('Foto/FotoList',[ 'fotos' => $transaction]);
}
please give me some clue or hint, solution to fix this problems
Thankyou in advance
2
Answers
You should persist the query result to a variable before pagination. This might work:
If I understood you correctly, your conditions work properly only on the first page. On any other they don’t work. If that’s the case, I think this code should solve your problem, because it worked for me:
Hope this helps! 🙂