Level 1
I found the solution, Its very simple, I just removed 'in' and use
I just added '%' before and after all keys
$posts = Post::where('title', 'like', $keys)->('body', 'like', $keys)->get();
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
I have a posts table (Post model), I want to search for a string like this (Laravel query builder), and I want to search to run like the following:
1- explode search string to create array
$keys = ['Laravel', 'query', 'builder'];
2- search if any item in the array is found in post title or post body
$posts = Post::where('title', 'in', $keys)->orWhere('body', 'in', $keys)->get();
$posts return an empty array, I don't know if the previous eloquent statement has any thing wrong
I found the solution, Its very simple, I just removed 'in' and use
I just added '%' before and after all keys
$posts = Post::where('title', 'like', $keys)->('body', 'like', $keys)->get();
Please or to participate in this conversation.