user = $user; $this->sangh = $sangh; } /** * Execute the job. * * @return void */ public function handle() { try { $tokens = UserDeviceToken::where('user_id', $this->sangh->updated_by)->get()->toArray(); $pushData = []; $users = []; if ($tokens && $tokens > 0) { foreach ($tokens as $token) { $pushData['userToken'] = $token['token'] ?? []; $pushData['title'] = trans('notifications.notification_title.sangh_approved', ['sangh' => $this->sangh->name]); $pushData['body'] = trans('notifications.sangh.sangh_approved'); $pushData['image'] = ($this->user->avatar) ? $this->user->avatar : ""; $pushData['from_id'] = $this->user->id; $extraData = []; $extraData['user_id'] = $this->user->id ?? ''; $extraData['user_name'] = $this->user->name ?? ''; $extraData['type'] = trans('notifications.sangh_notification_type.sangh-approved'); $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 for approved sangh $notificationData = []; $notificationData['body'] = trans('notifications.sangh.sangh_approved'); $notificationData['user_id'] = $this->sangh->updated_by; $notificationData['type'] = trans('notifications.sangh_notification_type.sangh-approved'); $notificationData['title'] = trans('notifications.notification_title.sangh_approved', ['sangh' => $this->sangh->name]); $extraNotificationData = []; $extraNotificationData['sangh_id'] = $this->sangh->id ?? ''; $extraNotificationData['user_id'] = $this->user->id ?? ''; $extraNotificationData['name'] = $this->sangh->name ?? ''; $extraNotificationData['avatar'] = ($this->sangh->avatar) ? $this->sangh->avatar : ""; $extraNotificationData['user_type'] = 'sangh'; $extraNotificationData['created_at'] = date('Y/m/d H:i:s'); $notificationData['extraNotificationData'] = $extraNotificationData ?? []; if (!in_array($this->sangh->updated_by, $users)) { $users[$this->sangh->updated_by] = $this->sangh->updated_by; $this->storeNotification($notificationData); //Unread count increament unreadNotificationCounter($this->sangh->updated_by); } } catch (\Exception $ex) { Log::error($ex); } } }