flower
flower

Reputation: 91

Laravel DB facade how to express LIKE

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

Answers (2)

Rutvij Kothari
Rutvij Kothari

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

Abid Raza
Abid Raza

Reputation: 755

You might wanna use that statement like this.

DB::table('students')->where('name','LIKE',"%$keyword%")->orWhere('description','LIKE',"%$keyword%")->get();

Upvotes: 4

Related Questions