Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

smurfiez's avatar

How could I show all users by default.

At least till there are lots of users, what's the best way to show all users initially?

Even better, could all users be paginated and allow search as it's currently setup?

Thanks in advance.

0 likes
2 replies
jdc1898's avatar

Sure.

$users = App\User::all()->paginate(15);

or

$users = DB::table('users')->paginate(15);

SilenceBringer's avatar

@jdc1898 here

$users = App\User::all()->paginate(15);

you grab all the users from the database and then paginate it. It make no sence, because you can call paginate on model directly

$users = App\User::paginate(15);

@smurfiez as for search you can use something like

$users = User::where('name', 'like', '%' . $request->search . '%')->get();

Please or to participate in this conversation.