authorizeAccess(); $this->service->load('media'); $this->name = $this->service->name; $this->intro = $this->service->intro; $this->url_clearnet = $this->service->url_clearnet; $this->url_onion = $this->service->url_onion; $this->url_i2p = $this->service->url_i2p; $this->url_pkdns = $this->service->url_pkdns; $this->type = $this->service->type?->value ?? null; $this->contact = $this->service->contact; $this->anonymous = is_null($this->service->created_by); } protected function authorizeAccess(): void { // Allow edit if user is the creator or if service was created anonymously if (!is_null($this->service->created_by) && auth()->id() !== $this->service->created_by) { abort(403); } } protected function rules(): array { return [ 'name' => ['required', 'string', 'max:255'], 'type' => ['required', 'in:'.collect(SelfHostedServiceType::cases())->map(fn($c) => $c->value)->implode(',')], 'intro' => ['nullable', 'string'], 'url_clearnet' => ['nullable', 'url', 'max:255'], 'url_onion' => ['nullable', 'string', 'max:255'], 'url_i2p' => ['nullable', 'string', 'max:255'], 'url_pkdns' => ['nullable', 'string', 'max:255'], 'contact' => ['nullable', 'string'], 'anonymous' => ['boolean'], ]; } protected function validateAtLeastOneUrl(): void { if (empty($this->url_clearnet) && empty($this->url_onion) && empty($this->url_i2p) && empty($this->url_pkdns)) { $this->addError('url_clearnet', __('Mindestens eine URL muss angegeben werden.')); throw new \Illuminate\Validation\ValidationException( validator([], []) ); } } public function save(): void { $this->authorizeAccess(); $validated = $this->validate(); $this->validateAtLeastOneUrl(); $this->service->update([ 'name' => $validated['name'], 'type' => $validated['type'], 'intro' => $validated['intro'] ?? null, 'url_clearnet' => $validated['url_clearnet'] ?? null, 'url_onion' => $validated['url_onion'] ?? null, 'url_i2p' => $validated['url_i2p'] ?? null, 'url_pkdns' => $validated['url_pkdns'] ?? null, 'contact' => $validated['contact'] ?? null, 'created_by' => $this->anonymous ? null : ($this->service->created_by ?? auth()->id()), ]); if ($this->logo) { $this->service->clearMediaCollection('logo'); $this->service->addMedia($this->logo->getRealPath()) ->usingFileName($this->logo->getClientOriginalName()) ->toMediaCollection('logo'); $this->logo = null; $this->service->load('media'); } session()->flash('status', __('Service erfolgreich aktualisiert!')); } public function with(): array { return [ 'types' => collect(SelfHostedServiceType::cases())->map(fn($c) => ['value' => $c->value, 'label' => ucfirst($c->value)]), ]; } }; ?>