user = $user; $this->sangh = $sangh; $this->sanghMemberId = $sanghMemberId; $this->coreMember = $coreMember; $this->roleName = $roleName; } /** * Execute the job. * * @return void */ public function handle() { try { //Push Notification to admin when user send join request $tokens = UserDeviceToken::where('user_id', $this->sanghMemberId)->with('user')->get()->toArray(); $pushData = []; $users = []; if($tokens && $tokens > 0) { foreach ($tokens as $token) { $pushData['userToken'] = $token['token'] ?? []; $pushData['title'] = trans('notifications.notification_title.user_sent_join_request', ['sangh' => $this->sangh->name]); $pushData['body'] = trans('notifications.push_sangh.user_sent_join_request', ['user' => $this->user->name, 'sangh' => $this->sangh->name]); $pushData['image'] = ($this->user->avatar) ? $this->user->avatar : ""; $pushData['from_id'] = $this->sangh->id; $extraData = []; $extraData['from_id'] = $this->sangh->id; $extraData['user_id'] = $this->sanghMemberId ?? ''; $extraData['user_name'] = $this->user->name ?? ''; $extraData['user_type'] = 'sangh'; $extraData['type'] = trans('notifications.sangh_notification_type.user-sent-member-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'] = ($this->roleName) ? trans('notifications.sangh.user_sent_join_request_with_role', ['sangh' => $this->sangh->name, 'role' => $this->roleName]) : trans('notifications.sangh.user_sent_join_request', ['sangh' => $this->sangh->name]); $notificationData['user_id'] = $this->sanghMemberId; $notificationData['type'] = trans('notifications.sangh_notification_type.user-sent-member-request'); $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->user->name ?? ''; $extraNotificationData['avatar'] = ($this->user->avatar) ? $this->user->avatar : ""; $extraNotificationData['sangh_id'] = $this->sangh->id ?? ''; $extraNotificationData['sangh_name'] = $this->sangh->name ?? ''; $extraNotificationData['add_member'] = $this->coreMember; $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->sanghMemberId, $users)) { $users[$this->sanghMemberId] = $this->sanghMemberId; $this->storeNotification($notificationData); //Unread count increament unreadNotificationCounter($this->sanghMemberId); } } catch (\Exception $ex) { Log::error($ex); } } }