Here is my code
$search_term = "Hary Kumar";
$filterData = DB::table('signups')->where('name','LIKE',"%{$search_term}%");
If I am not wrong above code will give me result like:
select * from signups where name like "%Hary Kumar%"
But, I am trying to get
select * from signups where name like "%Hary%" or name like "%Kumar%"
CodePudding user response:
You are looking for a simple orWhere()
DB::table('signups')
->where('name', 'LIKE', "%{$first_term}%")
->orWhere('name', 'LIKE', "%{$second_term}%");
CodePudding user response:
I got my answer. Here is the code:
$search_values = explode(" ",$search_term);
DB::table('signups')
->orWhere(function ($query) use($search_values) {
foreach($search_values as $search_value)
$query->orwhere('name', 'like', '%' . $search_value .'%');})