Mysql
 sql >> Database >  >> RDS >> Mysql

query mysql laravel con multiple where orwhere e inner join

Ok, sembra che il tuo problema riguardi il nidificato dove

Prova questo:

$name = $_POST['name']; // I'd recommend you use Input::get('name') instead...

$user_list = DB::table('users')
    ->where('users.user_id' ,'=', $clientId)
    ->where(function($query) use ($name){
        $query->where('users.firstname', 'LIKE', '%'.$name.'%');
        $query->orWhere('users.lastname', 'LIKE', '%'.$name.'%');
        $query->orWhere('users.email', 'LIKE', '%'.$name.'%');
    })
    ->join('users_roles', 'users.id', '=', 'users_roles.user_id')
    ->where('users_roles.role_id', '=', Role::USER_PARTICIPANT)
    ->get();