jeudi 23 août 2018

Using variable (for loop) in Laravel's Query Builder

I have a query that needs to check multiple orWhere statements.

$cases = ['john', 'kate', 'mike', 'rob', 'josh', 'moe']

I want to use where as a for loop in this case.

Cat::where(function($q) use ($cases) {
   $q->where('name', 'john')->orWhere('name', 'kate'); // etc
})->get();

Is there a cleaner way to use this with a for loop so it chains orWhere on the fly?



from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/2BCqvre
via IFTTT

Aucun commentaire:

Enregistrer un commentaire