mardi 3 novembre 2015

how to handle Multiple Orwhere in Laravel

I'm working in Laravel 5 and am using the Orwhere clausule, my code to consult is this:

$estudiantes= Usuario::
        where('rol', '=', 'ESTUDIANTE')
            ->whereHas('perfil', function($query) use ($data){
                if($data!="")
                    $query->Where('doc_identidad', '=' ,$data)
                        ->orWhere('nombres','like','%'.$data.'%')
                        ->orWhere('apellidos','like','%'.$data.'%');
                dd($query);
            })->get();

So, I want to filter every Usuario with rol ESTUDIANTE that works very fine, then I want to filter which of these have doc_identidad or nombres or apellidos like you see, I have a dd($query) to see the tree of the query, and I noticed that the first where uses and instead of or. This is the tree:enter image description here

So, I have the next: where1 and where2 or where3 or where4

and I want: where1 and (where2 or where3 or where4) so, how should I do it? thanks!



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire