I am new to laravel query builder, I want to search multiple words entered in an input field for example if I type \"jhon doe\" I want to get any column that contains jhon o
$string = 'john doe';
// split on 1+ whitespace & ignore empty (eg. trailing space)
$searchValues = preg_split('/\s+/', $string, -1, PREG_SPLIT_NO_EMPTY);
$users = User::where(function ($q) use ($searchValues) {
foreach ($searchValues as $value) {
$q->Where('name', 'like', "%{$value}%");
}
})->get();
Using 'orWhere' will get you results for each keyword not results for keyword1 + keyword2...So all depends on what your looking for