route('organisation')); return inertia('registries/Index', [ 'registries' => $organisation->registries() ->latest() ->get(), ]); } public function create(Request $request): Response { Organisation::findOrFail($request->route('organisation')); return inertia('registries/Create', [ 'registryTypes' => array_values(RegistryType::toArray()), ]); } public function store(StoreRegistryRequest $request): RedirectResponse { $organisation = Organisation::findOrFail($request->route('organisation')); $organisation->registries()->create([ 'name' => $request->string('name')->toString(), 'type' => $request->enum('type', RegistryType::class), 'url' => rtrim($request->string('url')->toString(), '/'), 'credentials' => [ 'username' => $request->string('username')->toString(), 'password' => $request->string('password')->toString(), ], ]); return redirect() ->route('organisations.show', ['organisation' => $organisation->id]) ->with('success', 'Registry created.'); } public function show(Request $request): Response { $organisation = Organisation::findOrFail($request->route('organisation')); /** @var Registry $registry */ $registry = $organisation->registries()->findOrFail($request->route('registry')); $registryUrl = rtrim((string) $registry->url, '/'); $artifacts = BuildArtifact::query() ->with(['environment.application', 'builtByService']) ->whereHas('environment.application', fn ($query) => $query->where('organisation_id', $organisation->id)) ->when($registryUrl !== '', fn ($query) => $query->where('registry_ref', 'like', $registryUrl.'%')); return inertia('registries/Show', [ 'registry' => $registry, 'artifactCount' => (clone $artifacts)->count(), 'environmentCount' => (clone $artifacts)->distinct('environment_id')->count('environment_id'), 'artifacts' => $artifacts ->latest() ->paginate(20), ]); } public function edit(Request $request): Response { $organisation = Organisation::findOrFail($request->route('organisation')); $registry = $organisation->registries()->findOrFail($request->route('registry')); return inertia('registries/Edit', [ 'registry' => $registry, 'registryTypes' => array_values(RegistryType::toArray()), ]); } public function update(UpdateRegistryRequest $request): RedirectResponse { $organisation = Organisation::findOrFail($request->route('organisation')); /** @var Registry $registry */ $registry = $organisation->registries()->findOrFail($request->route('registry')); $credentials = $registry->credentials ?? []; $username = $request->string('username')->toString(); if ($request->filled('password')) { $credentials['password'] = $request->string('password')->toString(); } $credentials['username'] = $username; $registry->update([ 'name' => $request->string('name')->toString(), 'type' => $request->enum('type', RegistryType::class), 'url' => rtrim($request->string('url')->toString(), '/'), 'credentials' => $credentials, ]); return redirect() ->route('organisations.show', ['organisation' => $organisation->id]) ->with('success', 'Registry updated.'); } public function destroy(Request $request): RedirectResponse { $organisation = Organisation::findOrFail($request->route('organisation')); $registry = $organisation->registries()->findOrFail($request->route('registry')); $registry->delete(); return redirect() ->route('organisations.show', ['organisation' => $organisation->id]) ->with('success', 'Registry deleted.'); } }