complete Complete User Request Submission section RAD-1
This commit is contained in:
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests\Admin;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
use Illuminate\Validation\Rule;
|
||||
use App\Enums\PetTypeEnum;
|
||||
use App\Enums\PetGenderEnum;
|
||||
use App\Support\Converters\PersianToEnglish;
|
||||
|
||||
class PetRequest 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
|
||||
{
|
||||
return [
|
||||
'name' => ['required', 'string', 'max:255'],
|
||||
'type' => ['required', 'string', 'max:255', Rule::in(PetTypeEnum::values())],
|
||||
'gender' => ['required', 'string', 'max:255', Rule::in(PetGenderEnum::values())],
|
||||
'breed' => ['required', 'string', 'max:255'],
|
||||
'weight' => ['required', 'integer'],
|
||||
'sterilized' => ['required', 'boolean'],
|
||||
'birthday' => ['required', 'date'],
|
||||
];
|
||||
}
|
||||
|
||||
public function prepareForValidation()
|
||||
{
|
||||
$this->merge([
|
||||
'weight' => PersianToEnglish::toEnglish($this->weight),
|
||||
]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user