1

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?

flower
  • 91
  • 1
  • 10

2 Answers2

4

You might wanna use that statement like this.

DB::table('students')->where('name','LIKE',"%$keyword%")->orWhere('description','LIKE',"%$keyword%")->get();
Abid Raza
  • 745
  • 8
  • 15
2

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();
Rutvij Kothari
  • 1,253
  • 11
  • 22