sangh = $sangh; $this->allUser = $allUser; } /** * Execute the job. * * @return void */ public function handle() { try { $users = []; foreach ($this->allUser as $user) { $tokens = UserDeviceToken::where('user_id', $user->id)->get()->toArray(); $pushData = []; if (!empty($tokens)) { foreach ($tokens as $token) { $pushData['userToken'] = $token['token'] ?? ''; $pushData['title'] = trans('notifications.notification_title.sangh_created', ['sangh' => $this->sangh->name]); $pushData['body'] = trans('notifications.notification_title.sangh_descreption', ['sangh' => $this->sangh->name]); $pushData['image'] = ($user->avatar) ? $user->avatar : ""; $pushData['from_id'] = $user->id; $extraData = [ 'user_id' => $user->id ?? '', 'user_name' => $user->name ?? '', 'type' => trans('notifications.sangh_notification_type.created_sangh'), 'created_at' => now()->format('Y/m/d H:i:s'), 'os' => $token['os'] ? getPlatform($token['os']) : '' ]; $pushData['extraData'] = $extraData ?? []; $this->pushNotification($pushData, $extraData); } } //Store notification for created sangh $notificationData = []; $notificationData['user_id'] = $user->id; $notificationData['type'] = trans('notifications.sangh_notification_type.created_sangh'); $notificationData['title'] = trans('notifications.notification_title.sangh_created', ['sangh' => $this->sangh->name]); $notificationData['body'] = trans('notifications.notification_title.sangh_descreption', ['sangh' => $this->sangh->name]); $extraNotificationData = []; $extraNotificationData['sangh_id'] = $this->sangh->id ?? ''; $extraNotificationData['user_id'] = $user->id ?? ''; $extraNotificationData['name'] = $this->sangh->name ?? ''; $extraNotificationData['avatar'] = $this->sangh->avatar ?? ''; $extraNotificationData['user_type'] = 'sangh'; $extraNotificationData['created_at'] = date('Y/m/d H:i:s'); $notificationData['extraNotificationData'] = $extraNotificationData ?? []; if (!in_array($user->id, $users)) { $users[$user->id] = $user->id; $this->storeNotification($notificationData); unreadNotificationCounter($user->id); } } } catch (\Exception $ex) { Log::error($ex); } } }