35 lines
844 B
PHP
35 lines
844 B
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Queries\Faqs;
|
|
|
|
use App\Contracts\Query;
|
|
use App\Contracts\QueryInput;
|
|
use App\Contracts\QueryInputEmpty;
|
|
use App\Dto\FaqDto;
|
|
use App\Models\Faq;
|
|
use Illuminate\Support\Collection;
|
|
use Webmozart\Assert\Assert;
|
|
|
|
/**
|
|
* @implements \App\Contracts\Query<\App\Contracts\QueryInputEmpty, \Illuminate\Support\Collection<int, \App\Dto\FaqDto>>
|
|
*/
|
|
final readonly class GetFaqsQuery implements Query
|
|
{
|
|
/**
|
|
* @return \Illuminate\Support\Collection<int, \App\Dto\FaqDto>
|
|
*/
|
|
public function __invoke(QueryInput $input): Collection
|
|
{
|
|
Assert::isAOf(
|
|
$input,
|
|
QueryInputEmpty::class,
|
|
);
|
|
|
|
return Faq::query()
|
|
->orderBy('order', 'asc')
|
|
->get()
|
|
->map(fn (Faq $faq): FaqDto => FaqDto::fromModel($faq));
|
|
}
|
|
}
|