1185 0 0 0
Last Updated : 2025-04-28 23:24:58
when deleting the last record on pagination page , this will make that page be fully empty with no records ... this snippet will allow you to redirect to the main route when deleting the last record on pagination and the page is empty
just add this line in your controller
$messages = Message::where('type', 'received')->orderby('id', 'desc')->paginate(2);
if (request()->get('page') > 1 && $messages->isEmpty()) {
return redirect()->route('main route here');
}
// change $messages to any records name