35 lines
854 B
PHP
35 lines
854 B
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Http\Requests;
|
|
|
|
use Illuminate\Foundation\Http\FormRequest;
|
|
|
|
class CategoryRequest extends FormRequest
|
|
{
|
|
public function rules(): array
|
|
{
|
|
return [
|
|
'name' => 'required|string|min:3|max:25',
|
|
'slug' => 'required|string|min:3|max:25',
|
|
'priority' => 'required|numeric|min:0|max:10',
|
|
'default' => 'nullable|boolean',
|
|
'visible' => 'required|boolean',
|
|
];
|
|
}
|
|
|
|
protected function prepareForValidation(): void
|
|
{
|
|
$this->merge([
|
|
'default' => $this->toBoolean($this->default),
|
|
'visible' => $this->toBoolean($this->visible),
|
|
]);
|
|
}
|
|
|
|
private function toBoolean($booleable): bool
|
|
{
|
|
return filter_var($booleable, FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE);
|
|
}
|
|
}
|