Zhephard
Zhephard

Reputation: 360

Laravel Query Builder: MySQL 'LIKE' inside a multiple where conditioned query

Im trying to do a query where i have multiple conditions (including %LIKE% operator) but can't figure how to do it in Laravel's array way with query builder.

$where = ['category' => $c->id, 'name' => $c->name];
$q = Store::where($where)->get();

That way it would return an array of objects with the equal of the name, not the similar matches. Is it possible to do a %LIKE% search in that way?

Upvotes: 2

Views: 485

Answers (1)

Hyder B.
Hyder B.

Reputation: 12296

You should chain them like this:

DB::table('your-table-name')
    ->where('category','=','$c->id')
    ->where('name','=','$c->name')
    ->where('email', 'LIKE', '%test%')
    ->get();

Upvotes: 2

Related Questions