68 lines
1.3 KiB
PHP
68 lines
1.3 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Dto;
|
|
|
|
use App\Models\Faq;
|
|
use Illuminate\Contracts\Routing\UrlRoutable;
|
|
use Illuminate\Contracts\Support\Arrayable;
|
|
|
|
/**
|
|
* @implements Arrayable<string, mixed>
|
|
*/
|
|
final readonly class FaqDto implements Arrayable, UrlRoutable
|
|
{
|
|
public function __construct(
|
|
public int $id,
|
|
public string $question,
|
|
public string $answer,
|
|
public int $order,
|
|
) {
|
|
}
|
|
|
|
public static function fromModel(Faq $faq): self
|
|
{
|
|
return new self(
|
|
id: $faq->id,
|
|
question: $faq->question,
|
|
answer: $faq->answer,
|
|
order: $faq->order,
|
|
);
|
|
}
|
|
|
|
#[\Override]
|
|
public function getRouteKey(): mixed
|
|
{
|
|
return $this->id;
|
|
}
|
|
|
|
#[\Override]
|
|
public function getRouteKeyName(): string
|
|
{
|
|
return 'id';
|
|
}
|
|
|
|
#[\Override]
|
|
public function resolveRouteBinding($value, $field = null): mixed
|
|
{
|
|
return null;
|
|
}
|
|
|
|
#[\Override]
|
|
public function resolveChildRouteBinding($childType, $value, $field): mixed
|
|
{
|
|
return null;
|
|
}
|
|
|
|
#[\Override]
|
|
public function toArray(): array
|
|
{
|
|
return [
|
|
'id' => $this->id,
|
|
'question' => $this->question,
|
|
'answer' => $this->answer,
|
|
'order' => $this->order,
|
|
];
|
|
}
|
|
}
|