I have added this index()
method to the Controller for searching:
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() // ... });