59 lines
1.5 KiB
PHP
59 lines
1.5 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Http\Requests;
|
|
|
|
use App\Contracts\RequestFilterInterface;
|
|
use Illuminate\Foundation\Http\FormRequest;
|
|
|
|
class IndexTaskRequest extends FormRequest implements RequestFilterInterface
|
|
{
|
|
public function authorize(): bool
|
|
{
|
|
return true;
|
|
}
|
|
|
|
public function rules(): array
|
|
{
|
|
return [
|
|
'is_done' => ['nullable', 'boolean'],
|
|
'tag' => ['nullable', 'string', 'max:50'],
|
|
'q' => ['nullable', 'string', 'max:200'],
|
|
'sort' => ['nullable', 'in:created_at,due_at'],
|
|
'order' => ['nullable', 'in:asc,desc'],
|
|
'page' => ['nullable', 'integer', 'min:1'],
|
|
'per_page' => ['nullable', 'integer', 'min:1', 'max:' . config('filters.pagination.max_per_page')],
|
|
];
|
|
}
|
|
|
|
public function filters(): array
|
|
{
|
|
return [
|
|
'is_done',
|
|
'tag',
|
|
'search',
|
|
'sort',
|
|
];
|
|
}
|
|
|
|
public function values(): array
|
|
{
|
|
return [
|
|
'is_done' => $this->filled('is_done') ? (bool)$this->input('is_done') : null,
|
|
'tag' => $this->input('tag'),
|
|
'search' => $this->input('q'),
|
|
'sort' => [
|
|
'column' => $this->input('sort'),
|
|
'direction' => $this->input('order'),
|
|
],
|
|
];
|
|
}
|
|
|
|
public function perPage(): ?int
|
|
{
|
|
return (int)$this->input('per_page');
|
|
//?? config('filters.pagination.per_page')
|
|
}
|
|
}
|