route('user'); if (! $user instanceof User) { return false; } return $this->user()?->can('update', $user) ?? false; } protected function prepareForValidation(): void { if ($this->input('password') === '' || $this->input('password') === null) { $this->merge(['password' => null]); } } /** * @return array> */ public function rules(): array { /** @var User $target */ $target = $this->route('user'); return [ 'name' => ['required', 'string', 'max:255'], 'email' => [ 'required', 'string', 'lowercase', 'email', 'max:255', Rule::unique(User::class)->ignore($target->id), ], 'password' => ['nullable', 'confirmed', Password::defaults()], 'role' => ['required', Rule::in(['superadmin', 'user'])], ]; } }