first commit
This commit is contained in:
58
laravel/app/Http/Requests/IndexTaskRequest.php
Normal file
58
laravel/app/Http/Requests/IndexTaskRequest.php
Normal file
@@ -0,0 +1,58 @@
|
||||
<?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')
|
||||
}
|
||||
}
|
||||
28
laravel/app/Http/Requests/StoreTagRequest.php
Normal file
28
laravel/app/Http/Requests/StoreTagRequest.php
Normal file
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
class StoreTagRequest extends FormRequest
|
||||
{
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*/
|
||||
public function authorize(): bool
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array<string, \Illuminate\Contracts\Validation\ValidationRule|array<mixed>|string>
|
||||
*/
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
//
|
||||
];
|
||||
}
|
||||
}
|
||||
32
laravel/app/Http/Requests/StoreTaskRequest.php
Normal file
32
laravel/app/Http/Requests/StoreTaskRequest.php
Normal file
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
class StoreTaskRequest 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 [
|
||||
'title' => ['required', 'string', 'max:200'],
|
||||
'is_done' => ['nullable', 'boolean'],
|
||||
'due_at' => ['nullable', 'date', 'date_format:Y-m-d\TH:i:s\Z'],
|
||||
'tags' => ['nullable', 'array'],
|
||||
'tags.*' => ['string', 'max:50'],
|
||||
];
|
||||
}
|
||||
}
|
||||
28
laravel/app/Http/Requests/UpdateTagRequest.php
Normal file
28
laravel/app/Http/Requests/UpdateTagRequest.php
Normal file
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
class UpdateTagRequest extends FormRequest
|
||||
{
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*/
|
||||
public function authorize(): bool
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array<string, \Illuminate\Contracts\Validation\ValidationRule|array<mixed>|string>
|
||||
*/
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
//
|
||||
];
|
||||
}
|
||||
}
|
||||
32
laravel/app/Http/Requests/UpdateTaskRequest.php
Normal file
32
laravel/app/Http/Requests/UpdateTaskRequest.php
Normal file
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
class UpdateTaskRequest 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 [
|
||||
'title' => ['sometimes', 'required', 'string', 'max:200'],
|
||||
'is_done' => ['sometimes', 'boolean'],
|
||||
'due_at' => ['nullable', 'date', 'date_format:Y-m-d\TH:i:s\Z'],
|
||||
'tags' => ['nullable', 'array'],
|
||||
'tags.*' => ['string', 'max:50'],
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user