I have a filter query where it checks for three parameters id, keywords and status. It's working totally fine when I run this query in MySQL but when I try to run it through Laravel's query builder it's fetching all the results of that id.
Here is the query which I'm running in MySQL(and it's working fine like I mentioned):
SELECT * FROM `poems`
WHERE book_id = 2
AND p_english_keywords LIKE '%freedom%'
AND p_status = 1
And here is the Laravel's query builder code:
$poems = Poems
::where('book_id', '=', $filter, 'AND', 'p_english_keywords', 'LIKE', '%'.$query.'%', 'AND', 'p_status', '=', 1)
->orWhere('book_id', '=', $filter, 'AND', 'p_spanish_keywords', 'LIKE', '%'.$query.'%', 'AND', 'p_status', '=', 1)
->orWhere('book_id', '=', $filter, 'AND', 'p_german_keywords', 'LIKE', '%'.$query.'%', 'AND', 'p_status', '=', 1)
->orWhere('book_id', '=', $filter, 'AND', 'p_urdu_keywords', 'LIKE', '%'.$query.'%', 'AND', 'p_status', '=', 1)
->paginate(10);
This query looks totally fine and it's also working fine if a user removes the filter. It's searching for the keywords in user's language. But whenever a user applies a filter, it shows all the results from the filtered book instead of specific keywords in that book. Please Help!