49 lines
1.3 KiB
PHP
49 lines
1.3 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Requests;
|
|
|
|
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 true;
|
|
}
|
|
|
|
/**
|
|
* Get the validation rules that apply to the request.
|
|
*
|
|
* @return array<string, \Illuminate\Contracts\Validation\ValidationRule|array<mixed>|string>
|
|
*/
|
|
public function rules(): array
|
|
{
|
|
$userId = $this->route('id');
|
|
|
|
return [
|
|
'name' => 'sometimes|string|max:50|min:3',
|
|
'email' => [
|
|
'sometimes',
|
|
'email',
|
|
Rule::unique('users', 'email')->ignore($userId),
|
|
],
|
|
'role_id' => 'sometimes|exists:roles,id',
|
|
];
|
|
}
|
|
|
|
public function messages(): array
|
|
{
|
|
return [
|
|
'name.max' => 'O nome deve ter no máximo 50 caracteres',
|
|
'name.min' => 'O nome deve ter pelo menos 3 caracteres',
|
|
'email.email' => 'O email deve ser um email válido',
|
|
'email.unique' => 'O email já está em uso',
|
|
'role_id.exists' => 'Cargo não encontrado',
|
|
];
|
|
}
|
|
}
|