route('organisation')); $application = $organisation->applications()->findOrFail($request->route('application')); $environment = $application->environments()->findOrFail($request->route('environment')); return inertia('environment-attachments/Create', [ 'application' => $application, 'environment' => $environment, 'services' => $organisation->services() ->whereIn('type', [ServiceType::POSTGRES->value, ServiceType::VALKEY->value, ServiceType::CADDY->value]) ->orderBy('name') ->get(['id', 'name', 'type', 'category']), 'roles' => array_values(EnvironmentAttachmentRole::toArray()), ]); } public function store(StoreEnvironmentAttachmentRequest $request): RedirectResponse { $organisation = Organisation::findOrFail($request->route('organisation')); $application = $organisation->applications()->findOrFail($request->route('application')); $environment = $application->environments()->findOrFail($request->route('environment')); $service = $organisation->services()->findOrFail($request->integer('service_id')); app(AttachManagedService::class)->execute( environment: $environment, service: $service, role: $request->enum('role', EnvironmentAttachmentRole::class), name: $request->filled('name') ? $request->string('name')->toString() : null, envPrefix: $request->filled('env_prefix') ? $request->string('env_prefix')->toString() : null, isPrimary: $request->boolean('is_primary', true), ); return redirect() ->route('environments.show', [ 'organisation' => $organisation->id, 'application' => $application->id, 'environment' => $environment->id, ]) ->with('success', 'Managed service attached.'); } }