loggedInUser = $loggedInUser; $this->receiver = $receiver; $this->requestExist = $requestExist; } /** * Execute the job. * * @return void */ public function handle() { try { //Push Notification to user when someone accepts friend request $tokens = UserDeviceToken::where('user_id', $this->receiver->id)->get()->toArray(); $pushData = []; $users = []; if($tokens && $tokens > 0) { foreach ($tokens as $token) { $pushData['userToken'] = $token['token'] ?? []; $pushData['title'] = trans('notifications.notification_title.relationship_request_accepted',['user' => $this->loggedInUser->name]); $pushData['body'] = trans('notifications.push_relationship.accept_request',['user' => $this->loggedInUser->name]); $pushData['image'] = ($this->loggedInUser->avatar) ? $this->loggedInUser->avatar : ""; $pushData['from_id'] = $this->loggedInUser->id; $extraData = []; $extraData['user_id'] = $this->loggedInUser->id ?? ''; $extraData['user_name'] = $this->loggedInUser->name ?? ''; $extraData['user_type'] = 'relationRequest'; $extraData['type'] = trans('notifications.relationship_notification_type.relationship-request-accepted'); $extraData['created_at'] = date('Y/m/d H:i:s'); $extraData['os'] = $token['os'] ? getPlatform($token['os']) : []; $pushData['extraData'] = $extraData ?? []; $this->pushNotification($pushData, $extraData); } } //Store Notification $notificationData = []; $notificationData['body'] = trans('notifications.relationship.accept_request'); $notificationData['user_id'] = $this->receiver->id; $notificationData['type'] = trans('notifications.relationship_notification_type.relationship-request-accepted'); $notificationData['title'] = trans('notifications.notification_title.relationship_request_accepted',['user' => $this->loggedInUser->name]); $extraNotificationData = []; $extraNotificationData['from_id'] = $this->loggedInUser->id ?? ''; $extraNotificationData['user_id'] = $this->loggedInUser->id ?? ''; $extraNotificationData['name'] = $this->loggedInUser->name ?? ''; $extraNotificationData['avatar'] = ($this->loggedInUser->avatar) ? $this->loggedInUser->avatar : ""; $extraNotificationData['relation'] = $this->requestExist->relation ?? ''; $extraNotificationData['relation_request_status'] = Constant::STATUS_ONE ?? ''; $extraNotificationData['notification_type'] = Constant::STATUS_TWO; $extraNotificationData['user_type'] = 'shravak'; $extraNotificationData['created_at'] = date('Y/m/d H:i:s'); $notificationData['extraNotificationData'] = $extraNotificationData ?? []; if (!in_array($this->receiver->id, $users)) { $users[$this->receiver->id] = $this->receiver->id; $this->storeNotification($notificationData); //Unread count increament unreadNotificationCounter($this->receiver->id); } } catch (\Exception $ex) { Log::error($ex); } } }