kamilcraft-api/app/Http/Requests/ProjectRequest.php

43 lines
1.1 KiB
PHP

<?php
declare(strict_types=1);
namespace App\Http\Requests;
use Illuminate\Foundation\Http\FormRequest;
class ProjectRequest extends FormRequest
{
public function rules(): array
{
return [
'title' => 'required|string|min:3|max:255',
'author' => 'required|string|min:3|max:50',
'categories' => 'nullable|string',
'release_date' => 'required|date:Y-m-d',
'update_date' => 'nullable|date:Y-m-d',
'image_small' => 'nullable|string',
'image_medium' => 'nullable|string',
'image_large' => 'nullable|string',
'project_url' => 'nullable|string',
'project_version' => 'nullable|string',
'description' => 'required|string|min:3',
'visible' => 'required|boolean'
];
}
protected function prepareForValidation(): void
{
$this->merge([
'visible' => $this->toBoolean($this->visible),
]);
}
private function toBoolean($booleable): bool
{
return filter_var($booleable, FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE);
}
}