Files
L-Ami-Fiduciaire/app/Http/Requests/UpdateUserRequest.php

39 lines
1.0 KiB
PHP
Raw Normal View History

<?php
namespace App\Http\Requests;
use App\Enums\UserGroup;
use App\Models\User;
use Illuminate\Contracts\Validation\ValidationRule;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Rule;
class UpdateUserRequest extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*/
public function authorize(): bool
{
return $this->user() !== null;
}
/**
* Get the validation rules that apply to the request.
*
* @return array<string, ValidationRule|array<mixed>|string>
*/
public function rules(): array
{
/** @var User $user */
$user = $this->route('user');
return [
'name' => ['required', 'string', 'max:255'],
'email' => ['required', 'string', 'email', 'max:255', Rule::unique(User::class)->ignore($user->id)],
'password' => ['nullable', 'string', 'min:8', 'confirmed'],
'group' => ['required', Rule::in(UserGroup::getValues())],
];
}
}