74 lines
		
	
	
		
			1.6 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
			
		
		
	
	
			74 lines
		
	
	
		
			1.6 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
<?php
 | 
						|
 | 
						|
declare(strict_types=1);
 | 
						|
 | 
						|
namespace App\Http\Requests\Post;
 | 
						|
 | 
						|
use App\Http\Requests\InvalidDataResponseTrait;
 | 
						|
use App\Services\QueryRequestModifiers\Post\PostFilter;
 | 
						|
use App\Services\QueryRequestModifiers\Post\PostFilterDTO;
 | 
						|
use App\Services\QueryRequestModifiers\Post\PostOrder;
 | 
						|
use App\Services\QueryRequestModifiers\Post\PostOrderDTO;
 | 
						|
use Illuminate\Foundation\Http\FormRequest;
 | 
						|
 | 
						|
class ListPostRequest extends FormRequest
 | 
						|
{
 | 
						|
    use InvalidDataResponseTrait;
 | 
						|
 | 
						|
    public function __construct(
 | 
						|
        private readonly PostOrder $postOrder,
 | 
						|
        private readonly PostFilter $postFilter,
 | 
						|
    ) {
 | 
						|
    }
 | 
						|
 | 
						|
    /**
 | 
						|
     * @return array<string, string>
 | 
						|
     */
 | 
						|
    public function all($keys = null): array
 | 
						|
    {
 | 
						|
        $request = parent::all($keys);
 | 
						|
 | 
						|
        $request['page'] = $this->route('page');
 | 
						|
 | 
						|
        return $request;
 | 
						|
    }
 | 
						|
 | 
						|
    public function authorize(): bool
 | 
						|
    {
 | 
						|
        return true;
 | 
						|
    }
 | 
						|
 | 
						|
    /**
 | 
						|
     * @return array<string, string>
 | 
						|
     */
 | 
						|
    public function rules(): array
 | 
						|
    {
 | 
						|
        return [
 | 
						|
            'page' => 'required|integer|min:1',
 | 
						|
            ... $this->postFilter->validateRules(),
 | 
						|
            ... $this->postOrder->validateRules()
 | 
						|
        ];
 | 
						|
    }
 | 
						|
 | 
						|
    /**
 | 
						|
     * @return array<string, string>
 | 
						|
     */
 | 
						|
    public function attributes(): array
 | 
						|
    {
 | 
						|
        return [
 | 
						|
            'page' => 'page number',
 | 
						|
        ];
 | 
						|
    }
 | 
						|
 | 
						|
 | 
						|
    public function filters(): ?PostFilterDTO
 | 
						|
    {
 | 
						|
        return $this->postFilter->makeFromRequest($this);
 | 
						|
    }
 | 
						|
 | 
						|
    public function order(): ?PostOrderDTO
 | 
						|
    {
 | 
						|
        return $this->postOrder->makeFromRequest($this);
 | 
						|
    }
 | 
						|
}
 |