organization = $organization; if ($location?->exists) { $this->location = $location; $this->name = $location->name; $this->address_line_1 = $location->address_line_1 ?? ''; $this->address_line_2 = $location->address_line_2 ?? ''; $this->city = $location->city ?? ''; $this->region = $location->region ?? ''; $this->postal_code = $location->postal_code ?? ''; $this->country = $location->country ?? ''; $this->phone = $location->phone ?? ''; $this->is_primary = $location->is_primary; } } public function save(): void { $validated = $this->validate([ 'name' => 'required|string|max:255', 'address_line_1' => 'nullable|string|max:255', 'address_line_2' => 'nullable|string|max:255', 'city' => 'nullable|string|max:255', 'region' => 'nullable|string|max:255', 'postal_code' => 'nullable|string|max:255', 'country' => 'nullable|string|max:255', 'phone' => 'nullable|string|max:255', 'is_primary' => 'boolean', ]); if ($validated['is_primary']) { $this->organization->locations() ->when($this->location?->exists, fn ($query) => $query->whereKeyNot($this->location->id)) ->update(['is_primary' => false]); } if ($this->location?->exists) { $this->location->update($validated); session()->flash('status', "Site \"{$this->location->name}\" mis à jour."); } else { $this->organization->locations()->create($validated); session()->flash('status', "Site \"{$this->name}\" créé."); } $this->redirectRoute('organizations.locations.index', $this->organization, navigate: true); } }; ?>
{{ $organization->name }}