If you dd your users in the controller is it a collection?
Going to need a little more info, this looks fine.
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
i want to return all users in my database to the view but i keep getting the error
Undefined variable: users (View: C:\xampp\htdocs\AjaxLav5.0\resources\views\pages\searchUsers.blade.php)
This is my Controller
public function allUsers() {
$users = User::all();
//return $users;
return view('pages.searchUsers')->with('users', $users);
}
This is my blade
@if (count($users) > 0)
@foreach($users as $user)
{{$user->name}}
@endforeach
@endif
Please or to participate in this conversation.