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