Hi guys can somebody help me
I need to search for users in a table from an text input
i did it if we search just by the name or by the last name but cant do it if we write both the name and the last name in the text input
this is the code when we write just the name or the last name:
$data = User::where('name', 'LIKE', '%'. $search .'%')
->orWhere('firstname', 'LIKE', '%'. $search .'%')
->get();
i think its something like this but it doesn't work :D
first i did split the text given from the input here is the code
$words = explode(' ', $search);
$firstword = $words[0];
$lastword = $words[1];
$data = User::where('name', 'LIKE', '%'. $firstword .'%')
->where('firstname', 'LIKE', '%'. $lastword .'%')
->get();
You could do something like this to search for all the words against both the first name and last name columns:
your problem was this (orWhere instead where):
) you can do something like this
hope this helps