user = $user; $this->post = $post; $this->friend = $friend; } /** * Execute the job. * * @return void */ public function handle() { try { //Push Notification to friends $tokens = UserDeviceToken::where('user_id', $this->friend)->get()->toArray(); $pushData = []; $users = []; if($tokens && $tokens > 0) { foreach ($tokens as $token) { $pushData['userToken'] = $token['token'] ?? []; $pushData['title'] = trans('notifications.notification_title.user_friend_post'); $pushData['body'] = trans('notifications.push_friend_post.new_post',['user' => $this->user->name]); $pushData['image'] = ($this->user->avatar) ? $this->user->avatar : ""; $pushData['from_id'] = $this->post->id; $extraData = []; $extraData['from_id'] = $this->post->id; $extraData['user_id'] = $this->user->id ?? ''; $extraData['user_name'] = $this->user->name ?? ''; $extraData['user_type'] = 'shravak'; $extraData['type'] = trans('notifications.friend_post_type.new-post'); $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_post.post'); $notificationData['user_id'] = $this->friend; $notificationData['type'] = trans('notifications.friend_post_type.new-post'); $notificationData['title'] = trans('notifications.notification_title.user_friend_post'); $extraNotificationData = []; $extraNotificationData['from_id'] = $this->post->id ?? ''; $extraNotificationData['user_id'] = $this->user->id ?? ''; $extraNotificationData['name'] = $this->user->name ?? ''; $extraNotificationData['avatar'] = ($this->user->avatar) ? $this->user->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->friend, $users)) { $users[$this->friend] = $this->friend; $this->storeNotification($notificationData); //Unread count increament unreadNotificationCounter($this->friend); } } catch (\Exception $ex) { Log::error($ex); } } }