id ?? Auth::guard('jwt_mobile')->user()->id; $check = CustomerChatNotifCount::where('customer_id', $customerId)->where('user_id', $userId)->first(); if (!$check) { CustomerChatNotifCount::create([ 'customer_id' => $customerId, 'user_id' => $userId, 'count' => 0 ]); } else { CustomerChatNotifCount::where('customer_id', $customerId)->where('user_id', $userId)->update([ 'count' => 0 ]); } return CustomerChatNotifCount::where('customer_id', $customerId)->where('user_id', $userId)->first(); } public function update(CustomerChatAttr $CustomerChatAttr) { $userId = Auth::user()->id ?? Auth::guard('jwt_mobile')->user()->id; if ($CustomerChatAttr->getIsLog()) { CustomerChatNotifCount::where('customer_id', $CustomerChatAttr->getCustomerId())->update([ 'count' => DB::raw('count+1') ]); } else { CustomerChatNotifCount::where('customer_id', $CustomerChatAttr->getCustomerId())->where('user_id', '<>', $userId)->update([ 'count' => DB::raw('count+1') ]); } return CustomerChatNotifCount::where('customer_id', $CustomerChatAttr->getCustomerId())->where('user_id', $userId)->first(); } public function checkData($customerId, $userId) { return CustomerChatNotifCount::where('user_id', $userId)->where('customer_id', $customerId)->first(); } public function getCount($customerId, $userId) { return CustomerChatNotifCount::where('customer_id', $customerId)->where('user_id', $userId)->first()->count; } public function existUser($userId) { return CustomerChatNotifCount::where('user_id', $userId)->first(); } public function sumCountByUserId($userId) { return CustomerChatNotifCount::where('user_id', $userId)->sum('count'); } }