48 lines
1.3 KiB
PHP
48 lines
1.3 KiB
PHP
<?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()
|
|
{
|
|
if ($this->filled('weight')) {
|
|
$this->merge([
|
|
'weight' => PersianToEnglish::toEnglish($this->weight),
|
|
]);
|
|
}
|
|
}
|
|
}
|