[Help] Create Loop Search Query
hello,
I really need help for build my search query, my code is like this
// example keyword : Leonardo+Da+Vinci
$keyword = str_replace('+', ' ', $request->keyword);
$db = Book::where('title', 'like', "%$keyword%")
->take(10)
->get();
return $db;
how to set search like this
$db = Book::where('title', 'like', '%Leonardo%'. '%Da%' . '%Vinci%')
->take(10)
->get();
return $db;
Please Help Me with this
Something like this (not tested)
$keywords = explode(' ', $keyword);
$db = Book::where('title', 'like', '%' . implode('%', $keywords) . '%')
->take(10)
->get();
I also think you can just replace the + by a %.
$db = Book::where('title', 'like', '%' . str_replace('+', '%', $request->keyword) . '%')
->take(10)
->get();
@postitief
that was awesome, thank you very much sir.
Please or to participate in this conversation.