Is it possible to group where clauses in Eloquent?
I know I had seen that it was doable when using the DB facade, but I haven't found anything in the docs regarding it using the fluid Eloquent syntax.
Yes, it is possible for example you can do something like:
User::where('username','john doe')
->where(function($query)
{
$query->where('age','>',30)
->orWhere('email','=','johndoe@xyz.com');
})
->toSql();
The above statements will generate the following SQL:
select * from `users` where `username` = ? and (`age` > ? or `email` = ?)
Helped here too... thanks!
Thanks. Just the example I was looking for.
It worked for me by this code:
public static function seachFiles($q, $categoryId)
{
return static::where('category_id', '=' ,$categoryId)
->where(function ($query) use ($q) {
$query->where('file_name', 'LIKE', "%$q%")
->orWhere('file_code', 'LIKE', "%$q%")
->orWhere('description', 'LIKE', "%$q%");
})
->get();
}
hope this helps.
Please or to participate in this conversation.