loggedInUser = $loggedInUser; $this->receiver = $receiver; } /** * 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.friend_request_accepted',['user' => $this->loggedInUser->name]); $pushData['body'] = trans('notifications.push_friend_request.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'] = 'friendRequest'; $extraData['type'] = trans('notifications.friend_request_notification_type.friend-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.friend_request.accept_request'); $notificationData['user_id'] = $this->receiver->id; $notificationData['type'] = trans('notifications.friend_request_notification_type.friend-request-accepted'); $notificationData['title'] = trans('notifications.notification_title.friend_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['notification_type'] = Constant::STATUS_ONE; $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); } } }