organization = $organization; $this->technicianUserId = $organization->technician_user_id; $this->ispName = $organization->isp_name ?? ''; $this->publicIpsText = implode("\n", $organization->public_ips ?? []); } public function save(): void { $validated = $this->validate([ 'technicianUserId' => 'nullable|exists:users,id', 'ispName' => 'nullable|string|max:255', 'publicIpsText' => 'nullable|string', ]); $ips = collect(preg_split('/[\s,]+/', (string) $validated['publicIpsText'], -1, PREG_SPLIT_NO_EMPTY)) ->unique() ->values(); if ($ips->contains(fn ($ip) => filter_var($ip, FILTER_VALIDATE_IP) === false)) { $this->addError('publicIpsText', 'Une ou plusieurs adresses IP sont invalides.'); return; } $this->organization->update([ 'technician_user_id' => $validated['technicianUserId'], 'isp_name' => $validated['ispName'] !== '' ? $validated['ispName'] : null, 'public_ips' => $ips->all(), ]); session()->flash('status', "Fiche d'identité mise à jour."); } public function addProvider(): void { $validated = $this->validate([ 'newProviderId' => 'required|exists:providers,id', 'newProviderLabel' => 'nullable|string|max:255', ]); $label = $validated['newProviderLabel'] ?: null; $alreadyLinked = $this->organization->providers() ->wherePivot('provider_id', $validated['newProviderId']) ->wherePivot('label', '=', $label) ->exists(); if ($alreadyLinked) { $this->addError('newProviderId', 'Ce prestataire est déjà lié avec ce libellé.'); return; } $this->organization->providers()->attach($validated['newProviderId'], ['label' => $label]); $this->reset(['newProviderId', 'newProviderLabel']); } public function removeProvider(int $pivotId): void { DB::table('organization_provider') ->where('id', $pivotId) ->where('organization_id', $this->organization->id) ->delete(); } public function with(): array { return [ 'technicians' => User::role(['Administrateur', 'Technicien'])->orderBy('name')->get(), 'availableProviders' => Provider::orderBy('name')->get(), 'providers' => $this->organization->providers()->orderBy('name')->get(), ]; } }; ?>

{{ $organization->name }}

Fiche d'identité informatique

@if (session('status'))
{{ session('status') }}
@endif
@error('technicianUserId')

{{ $message }}

@enderror
@error('ispName')

{{ $message }}

@enderror
@error('publicIpsText')

{{ $message }}

@enderror

Prestataires

@error('newProviderId')

{{ $message }}

@enderror
@if ($availableProviders->isEmpty())

Aucun prestataire n'existe encore. En créer un.

@endif