class EloquentNewsRepository implements NewsRepositoryInterface
{
protected array $relations = [];
public function all(): Collection
{
return News::with('users', 'comments', 'news')->get();
}
public function findByID(int $id): ?News
{
return News::findOrFail($id);
}
public function findByTitle(string $title): Collection
{
return News::whereTitleEn($title)->get();
}
public function paginate(int $pageSize = 6): LengthAwarePaginator
{
return News::with($this->relations)->paginate($pageSize);
}
}
я понимаю(не совсем), что в данном случае репозиторий использовать глупо, но мне в учебных целях, как лучше сделать, вызов со связамии, чтобы когда надо подрубать их
на уме такое есть
public function paginate(array $relations = $this->relations, int $pageSize = 6): LengthAwarePaginator
{
collect($relations)->merge($this->relations);
return News::with($this->relations)->paginate($pageSize);
}