*/ public array $organization_ids = []; public function mount(?User $user = null): void { if ($user?->exists) { $this->user = $user; $this->name = $user->name; $this->email = $user->email; $this->role = $user->getRoleNames()->first() ?? ''; $this->is_msp_staff = (bool) $user->is_msp_staff; $this->organization_ids = $user->organizations->pluck('id')->all(); } } public function save(): void { $validated = $this->validate([ 'name' => 'required|string|max:255', 'email' => ['required', 'email', 'max:255', Rule::unique('users', 'email')->ignore($this->user?->id)], 'password' => [$this->user?->exists ? 'nullable' : 'required', 'string', Password::default(), 'confirmed'], 'role' => 'required|exists:roles,name', 'is_msp_staff' => 'boolean', 'organization_ids' => 'array', 'organization_ids.*' => 'exists:organizations,id', ]); $attributes = [ 'name' => $validated['name'], 'email' => $validated['email'], 'is_msp_staff' => $validated['is_msp_staff'], ]; if (! empty($validated['password'])) { $attributes['password'] = Hash::make($validated['password']); } if ($this->user?->exists) { $this->user->update($attributes); } else { $this->user = User::create($attributes); } $this->user->syncRoles([$this->role]); $this->user->organizations()->sync($this->organization_ids); session()->flash('status', "Utilisateur « {$this->user->name} » enregistré."); $this->redirectRoute('users.index', navigate: true); } public function with(): array { return [ 'roles' => Role::orderBy('name')->get(), 'organizations' => Organization::orderBy('name')->get(), ]; } }; ?>

Gestion des utilisateurs

{{ $user?->exists ? 'Modifier l\'utilisateur' : 'Nouvel utilisateur' }}

@error('name')

{{ $message }}

@enderror
@error('email')

{{ $message }}

@enderror
@error('password')

{{ $message }}

@enderror
@error('role')

{{ $message }}

@enderror
@unless ($is_msp_staff)
@forelse ($organizations as $organization) @empty

Aucune organisation.

@endforelse
@endunless
Annuler