Skip to content
Advertisement

Laravel 8: Search Form Does Not Seem To Be Working

I have added this index() method to the Controller for searching:

enter image description here

But now the problem is it does not work, so what is going wrong out there?

Advertisement

Answer

You haven’t defined $search variable and are not passing it into the callback function correctly. Try something like below:

$search = request('search') ?? null;

User::when($search, function($query) use ($search) {
    return $query->where() // ...
});
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement