Skip to content
Advertisement

Laravel Query with Implode

i have an array with values

JavaScript

So i want search these three items from tables using like query

JavaScript

I tried where('primary_skill ', 'like', '%' . implode("' OR primary_skill LIKE '%", $skill_name) .'%') which is not working for me.Any help would be highly appreciated.

Advertisement

Answer

->where(‘primary_skill ‘, ‘like’, ‘%’ . implode(“‘ OR primary_skill LIKE ‘%”, $skill_name) .’%’)

Above line is incorrect since you can’t inject multiple where inside a single where condition. QueryBuilder will just take that as a string for comparison.

You can use regexp to match each value with a regular expression created from your $skill_name array as

JavaScript

This would get compiled as

JavaScript
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement