getFirebaseJsonPath(); $factory = (new Factory) ->withServiceAccount($firebaseFile); $push = $factory->createMessaging(); $relation = $this->user->packageNames() ->where('package_names.id', $this->packageName->id) ->first(); if (!$relation || !$relation->pivot?->fcm_token) { return; // skip if no token } $fcmToken = $relation->pivot->fcm_token; if (!$fcmToken) { return; } $message = CloudMessage::fromArray([ 'token' => $fcmToken, 'notification' => [ 'title' => $this->title, 'body' => $this->description, ], 'data' => $this->data ]); $push->send($message); } /** * Get Firebase JSON file path from Media Library for the package. */ private function getFirebaseJsonPath(): ?string { $media = $this->packageName->getFirstMedia('firebase_json'); if (!$media) { return null; } return $media->getPath(); } }