Reputation: 91
I have a query:
DB::select('select * from student where name like "%?%" or description like "%?%"',[$keyword,$keyword])
but I got empty result, which shouldn't be. I think it might take "?" instead of my keyword, how should I modify it?
Upvotes: 1
Views: 502
Reputation: 1285
You can do it in this way as well:
$result = DB::table('students')->where(function ($query) use ($keyword) {
$query->orWhere('name', 'like', "%".$keyword."%");
$query->orWhere('description', 'like', "%".$keyword."%");
})->get();
Upvotes: 2
Reputation: 755
You might wanna use that statement like this.
DB::table('students')->where('name','LIKE',"%$keyword%")->orWhere('description','LIKE',"%$keyword%")->get();
Upvotes: 4