I’m trying to use withQueryString() to $users
$users = $usersQuery->paginate(10);
like this
$users = $usersQuery->paginate(10)->withQueryString();
But I got an error ‘Undefined method withQueryString()’
This is my code
public function index(Request $request)
{
$usersQuery = User::with('userType');
// Filter by name
if ($request->name != null) {
$usersQuery->where('name', 'like', '%' . $request->name . '%');
}
// Filter by role
if ($request->user_type_id != null) {
$usersQuery->where('user_type_id', $request->user_type_id);
}
// Filter by role
if ($request->suspended != null) {
$usersQuery->where('suspended', $request->suspended);
}
$users = $usersQuery->paginate(10);
return view('admin.users.index', [
'users' => $users,
'title' => 'Users'
]);
}
If i use withQueryString without on User::paginate(10) without eager loading it has no errors. Any thoughts on how to resolve this? I’m using Laravel 11
New contributor
Vira Damayanti is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.