I have a CRUD system where the administrator can manage users.
The users overview has a pagination function:
public function index()
{
$users = User::first()->paginate(5);
return view('users.index', compact('users'));
}
Which then goes through a foreach
in my index.blade.php
file. And this works perfectly.
Untill the Administrator decides to delete all database records. This gives me the following error:
Call to a member function paginate() on null
How should I fix this error?
I want it to show the page but just not execute the Foreach
when there are no results.