32 lines
637 B
PHP
32 lines
637 B
PHP
<?php
|
|
|
|
namespace App\Set;
|
|
|
|
class EloquentSetRepository implements SetRepository
|
|
{
|
|
public function find(int $id): ?Set
|
|
{
|
|
$model = SetModel::find($id);
|
|
|
|
return $model === null ? null : $this->toDomain($model);
|
|
}
|
|
|
|
public function getAll(): array
|
|
{
|
|
$models = SetModel::orderBy('id')->get();
|
|
$sets = [];
|
|
foreach ($models as $model) {
|
|
$sets[] = $this->toDomain($model);
|
|
}
|
|
|
|
return $sets;
|
|
}
|
|
|
|
private function toDomain(SetModel $model): Set
|
|
{
|
|
return new Set(
|
|
id: $model->id,
|
|
name: $model->name,
|
|
);
|
|
}
|
|
}
|