user = $user; $this->sangh = $sangh; $this->member = $member; $this->roleName = $roleName; $this->isCoreCommittee = $isCoreCommittee; } /** * Execute the job. * * @return void */ public function handle() { try { //Push Notification to user when admin invites user $tokens = UserDeviceToken::where('user_id', $this->member)->get()->toArray(); $pushData = []; $users = []; if($tokens && $tokens > 0) { foreach ($tokens as $token) { $pushData['userToken'] = $token['token'] ?? []; $pushData['title'] = trans('notifications.notification_title.sangh_added_member', ['sangh' => $this->sangh->name]); $pushData['body'] = trans('notifications.push_sangh.sangh_admin_invite_member', ['sangh' => $this->sangh->name, 'role' => $this->roleName ?? 'Member']); $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->sangh->name ?? ''; $extraData['user_type'] = 'sangh'; if ($this->isCoreCommittee != Constant::NULL) { $extraData['type'] = trans('notifications.sangh_notification_type.sangh-added-committee-member'); } else { $extraData['type'] = trans('notifications.sangh_notification_type.sangh-added-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.sangh_admin_invite_member', ['role' => $this->roleName ?? 'Member']); $notificationData['user_id'] = $this->member; if ($this->isCoreCommittee != Constant::NULL) { $notificationData['type'] = trans('notifications.sangh_notification_type.sangh-added-committee-member'); } else { $notificationData['type'] = trans('notifications.sangh_notification_type.sangh-added-member'); } $notificationData['title'] = trans('notifications.notification_title.sangh_added_member', ['sangh' => $this->sangh->name]); $extraNotificationData = []; $extraNotificationData['from_id'] = $this->user->id ?? ''; $extraNotificationData['user_id'] = $this->user->id ?? ''; $extraNotificationData['name'] = $this->sangh->name ?? ''; $extraNotificationData['avatar'] = ($this->sangh->avatar) ? $this->sangh->avatar : ""; $extraNotificationData['add_member'] = true; $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->member, $users)) { $users[$this->member] = $this->member; $this->storeNotification($notificationData); unreadNotificationCounter($this->member); //Unread count increament unreadSanghInviteCounter($this->member, Constant::STATUS_ONE); //Pending invitation badge unreadSanghMenuCounter($this->member, Constant::STATUS_ONE); //Pending sangh menu badge } } catch (\Exception $ex) { Log::error($ex); } } }