36 lines
935 B
PHP
36 lines
935 B
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Queries\Slides;
|
|
|
|
use App\Contracts\Query;
|
|
use App\Dto\SlideDto;
|
|
use App\Models\Slide;
|
|
use App\Services\DataTableService;
|
|
use Illuminate\Contracts\Pagination\LengthAwarePaginator;
|
|
|
|
/**
|
|
* @implements \App\Contracts\Query<\Illuminate\Contracts\Pagination\LengthAwarePaginator<int, \App\Dto\SlideDto>>
|
|
*/
|
|
final readonly class GetPaginatedSlidesQuery implements Query
|
|
{
|
|
public function __construct(
|
|
private DataTableService $dataTable,
|
|
) {
|
|
}
|
|
|
|
/**
|
|
* @return \Illuminate\Contracts\Pagination\LengthAwarePaginator<int, \App\Dto\SlideDto>
|
|
*/
|
|
public function execute(): LengthAwarePaginator
|
|
{
|
|
$query = Slide::query();
|
|
|
|
$this->dataTable->sortQuery(Slide::class, $query);
|
|
|
|
$paginator = $this->dataTable->paginateQuery($query);
|
|
|
|
return $paginator->through(fn (Slide $slide): SlideDto => SlideDto::fromModel($slide));
|
|
}
|
|
}
|