34 lines
768 B
PHP
34 lines
768 B
PHP
<?php
|
|
|
|
namespace App\Http\Requests;
|
|
|
|
use Illuminate\Foundation\Http\FormRequest;
|
|
use Illuminate\Validation\Rule;
|
|
|
|
class SearchRequest extends FormRequest
|
|
{
|
|
public function authorize(): bool
|
|
{
|
|
return true;
|
|
}
|
|
|
|
public function rules(): array
|
|
{
|
|
return [
|
|
'q' => ['required', 'string', 'min:2', 'max:100'],
|
|
'type' => ['required', Rule::in(['meals', 'users'])],
|
|
'page' => ['sometimes', 'integer', 'min:1'],
|
|
'per_page' => ['sometimes', 'integer', 'min:1', 'max:50'],
|
|
];
|
|
}
|
|
|
|
protected function prepareForValidation(): void
|
|
{
|
|
if ($this->has('q')) {
|
|
$this->merge([
|
|
'q' => trim((string) $this->input('q')),
|
|
]);
|
|
}
|
|
}
|
|
}
|