dialog_id | user_id
$dialogs = DB::table('dialogs')
->leftJoin('users', function ($join) {
$join->on('users.id', '=', 'dialogs.recipient_id')
->where('dialogs.user_id','=', Auth::user()->id)
->orOn('users.id', '=', 'dialogs.user_id')
->where('dialogs.recipient_id','=', Auth::user()->id);
})
->leftJoin('user_attributes','user_attributes.user_id','=','users.id')
->select('user_attributes.fullname','user_attributes.avatar','user_attributes.age','users.email','dialogs.id','users.id as user')
->where('dialogs.user_id','=', Auth::user()->id)
->orWhere('dialogs.recipient_id','=', Auth::user()->id)->distinct('dialogs.id')
->get();
$dialogs = DB::table('dialogs')
->leftJoin('users', function ($join) {
$join->on('users.id', '=', 'dialogs.recipient_id')
->where('dialogs.user_id','=', Auth::user()->id)
->orOn('users.id', '=', 'dialogs.user_id')
->where('dialogs.recipient_id','=', Auth::user()->id);
})
->leftJoin('user_attributes','user_attributes.user_id','=','users.id')
->select('user_attributes.fullname','user_attributes.avatar','user_attributes.age','users.email','dialogs.id','users.id as user')
->where('dialogs.user_id','=', Auth::user()->id)
->whereNotExists(function ($query) {
$query->select(DB::raw(1))
->from('dialog_ignores')
->whereRaw('dialog_ignores.dialog_id = dialogs.id')
->whereRaw('dialog_ignores.user_id = '.Auth::user()->id.'')
->whereRaw('dialog_ignores.ignore_user_id = dialogs.recipient_id');
})
->orWhere('dialogs.recipient_id','=', Auth::user()->id)->distinct('dialogs.id')
->whereNotExists(function ($query) {
$query->select(DB::raw(1))
->from('dialog_ignores')
->whereRaw('dialog_ignores.dialog_id = dialogs.id')
->whereRaw('dialog_ignores.user_id = '.Auth::user()->id.'')
->whereRaw('dialog_ignores.ignore_user_id = dialogs.user_id');
})
->get();