loggedInUser = $loggedInUser; $this->receiver = $receiver; $this->relationName = $relationName; } /** * Execute the job. * * @return void */ public function handle() { try { //Push Notification to user when someone send 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.new_relationship_request'); $pushData['body'] = trans('notifications.push_relationship.relation_request',['user' => $this->loggedInUser->name,'relation' => $this->relationName]); $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'); $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.relation_request',['relation' => $this->relationName]); $notificationData['user_id'] = $this->receiver->id; $notificationData['type'] = trans('notifications.relationship_notification_type.relationship-request'); $notificationData['title'] = trans('notifications.notification_title.new_relationship_request'); $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'] = $data['relation'] ?? ''; $extraNotificationData['relation_request_status'] = Constant::STATUS_ZERO ?? ''; $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); } } }