In Laravel when I use the length aware pagination, let’s assume I was on the last page of the data set and I deleted all the records on that page, Laravel will return an empty data set for me since the page
query param references the page number for a none existent offset even though there might still be other records available.
UserController.php:
...
$pager = AppModelsUser::paginate(10);
return view('user_list', concat($pager));
user_list.blade.php:
@foreach($pager->data() as $user)
<div>
<span>{{$user->name}}</span>
<a href="{{route ('user.destroy', $user->id)}}">Delete</a>
</div>
@endforeach
In this case:
- How do tell that there are no more records for the current offset/page.
- How do I tell if the previous offset/page still contains active records.
- How do I elegantly force Laravel to redirect to the previous page without compromising user experience?