dimanche 30 avril 2017

Laravel Eloquent - (where) and (where or where or where)

I'm working on a search query for my data, I want to get only the available rows which are those who have value 0 in is_temp column and if the user send me a search query i would like to search this value in other columns

this is what I have now:

$clients = Company::where('guid',$guid)->first()
        ->clients()
        ->where('is_temp',0)
        ->orderBy('name', $sort_order)
        ->skip($per_page*($page-1))
        ->take($per_page);

if($search_query != ""){
     $clients = $clients->orWhere('name','LIKE','%'.$search_query.'%')
                        ->orWhere('email','LIKE','%'.$search_query.'%')
                        ->orWhere('vat_number','LIKE','%'.$search_query.'%')
                        ->orWhere('contact_name','LIKE','%'.$search_query.'%');
}

$response = [
    'clients' => $clients->get() 
];
return response()->json($response, 200);

but when I use it this way I get also the rows that the field is_temp equal to 1 so I need to use (where) and (where or where or where...)

how do i do that?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire