mysql - Laravel query builder grouping -


i have problem making laravel query:

i want example:

select * users (a = b) or (b = a) 

i have not working:

      $user = auth::user();     $id_user = $user->id;     $message = db::table('message')     ->where('sender_id', '=', $user->id)     ->where('reciver_id', '=', $id)     ->orwhere(function($query) use ($id,$id_user){       $query-->where('sender_id', '=', $id)        ->where('reciver_id', '=', $id_user);     })     ->join('users', function ($join) {        $join->on('users.id', '=', 'message.sender_id')->orwhere('users.id', '=', 'message.reciver_id');     })->select('users.*', 'message.topic', 'message.message', 'message.read', 'message.created_at date')     ->orderby('date')->get();      return $message;  

you should nest first 2 wheres in new one. see code below:

    $message = db::table('message')         ->where(function($query) use ($id,$id_user){             $query->where('sender_id', '=', $id_user)                 ->where('reciver_id', '=', $id);         })         ->orwhere(function($query) use ($id,$id_user){             $query->where('sender_id', '=', $id)                 ->where('reciver_id', '=', $id_user);         })         ->join('users', function ($join) {             $join->on('users.id', '=', 'message.sender_id')->orwhere('users.id', '=', 'message.reciver_id');         })->select('users.*', 'message.topic', 'message.message', 'message.read', 'message.created_at date')         ->orderby('date')->get(); 

Comments