New-Thanasoft/thanasoft-back/app/Http/Requests/UpdateClientGroupRequest.php

49 lines
1.4 KiB
PHP

<?php
namespace App\Http\Requests;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Rule;
class UpdateClientGroupRequest 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
{
$clientGroupId = $this->route('client_group') ? $this->route('client_group')->id : $this->route('id');
return [
'name' => [
'required',
'string',
'max:191',
Rule::unique('client_groups', 'name')->ignore($clientGroupId)
],
'description' => 'nullable|string',
];
}
public function messages(): array
{
return [
'name.required' => 'Le nom du groupe est obligatoire.',
'name.string' => 'Le nom du groupe doit être une chaîne de caractères.',
'name.max' => 'Le nom du groupe ne peut pas dépasser 191 caractères.',
'name.unique' => 'Un groupe avec ce nom existe déjà.',
'description.string' => 'La description doit être une chaîne de caractères.',
];
}
}