diff --git a/composer.json b/composer.json index 902edda..66d10c0 100644 --- a/composer.json +++ b/composer.json @@ -23,7 +23,7 @@ "cviebrock/eloquent-sluggable": "^10.0", "filament/filament": "^3.0-stable", "illuminate/contracts": "^10.0|^11.0", - "ibecsystems/admin-kit-core": "^3.1", + "ibecsystems/admin-kit-core": "^3.5", "ibecsystems/admin-kit-seo": "^3.4", "spatie/laravel-package-tools": "^1.14.0", "spatie/laravel-data": "^4.5", diff --git a/src/Actions/GetArticleBySlugAction.php b/src/Actions/GetArticleBySlugAction.php index a2f1eba..4415f85 100644 --- a/src/Actions/GetArticleBySlugAction.php +++ b/src/Actions/GetArticleBySlugAction.php @@ -5,7 +5,7 @@ namespace AdminKit\Articles\Actions; use AdminKit\Articles\Repositories\ArticleRepository; -use AdminKit\Articles\UI\API\DTO\ArticleDTO; +use AdminKit\Articles\UI\API\Data\ArticleData; use Spatie\LaravelData\Data; class GetArticleBySlugAction @@ -18,6 +18,6 @@ public function run(string $slug): Data { $article = $this->articleRepository->getBySlug($slug); - return ArticleDTO::from($article); + return ArticleData::from($article); } } diff --git a/src/Actions/GetArticleListAction.php b/src/Actions/GetArticleListAction.php index 453e607..e33421b 100644 --- a/src/Actions/GetArticleListAction.php +++ b/src/Actions/GetArticleListAction.php @@ -5,7 +5,7 @@ namespace AdminKit\Articles\Actions; use AdminKit\Articles\Repositories\ArticleRepository; -use AdminKit\Articles\UI\API\DTO\ArticleDTO; +use AdminKit\Articles\UI\API\Data\ArticleData; use Spatie\LaravelData\PaginatedDataCollection; class GetArticleListAction @@ -18,6 +18,6 @@ public function run(): PaginatedDataCollection { $articles = $this->articleRepository->getPaginatedList(); - return ArticleDTO::collection($articles)->except('content'); + return ArticleData::collect($articles, PaginatedDataCollection::class)->except('content'); } } diff --git a/src/Repositories/ArticleInterface.php b/src/Repositories/ArticleInterface.php index f5a37c7..a21e876 100644 --- a/src/Repositories/ArticleInterface.php +++ b/src/Repositories/ArticleInterface.php @@ -4,11 +4,10 @@ namespace AdminKit\Articles\Repositories; -use AdminKit\Core\Abstracts\Repositories\RepositoryInterface; use Illuminate\Database\Eloquent\Model; use Illuminate\Pagination\LengthAwarePaginator; -interface ArticleInterface extends RepositoryInterface +interface ArticleInterface { public function getPaginatedList(): LengthAwarePaginator; diff --git a/src/Repositories/ArticleRepository.php b/src/Repositories/ArticleRepository.php index 1121dd7..523f99e 100644 --- a/src/Repositories/ArticleRepository.php +++ b/src/Repositories/ArticleRepository.php @@ -13,14 +13,15 @@ class ArticleRepository extends AbstractRepository implements ArticleInterface { - public function model(): string + public function getModelClass(): string { return Article::class; } public function getPaginatedList(): LengthAwarePaginator { - return QueryBuilder::for($this->model()) + return QueryBuilder::for($this->getModelClass()) + ->with(['media', 'seo']) ->allowedFilters([ 'id', 'slug', @@ -41,7 +42,7 @@ public function getPaginatedList(): LengthAwarePaginator public function getBySlug(string $slug): Model { - return $this->model + return $this->model() ->where('slug', $slug) ->isPublished() ->firstOrFail(); diff --git a/src/UI/API/DTO/ArticleDTO.php b/src/UI/API/Data/ArticleData.php similarity index 74% rename from src/UI/API/DTO/ArticleDTO.php rename to src/UI/API/Data/ArticleData.php index ac0f825..fb314fa 100644 --- a/src/UI/API/DTO/ArticleDTO.php +++ b/src/UI/API/Data/ArticleData.php @@ -2,18 +2,15 @@ declare(strict_types=1); -namespace AdminKit\Articles\UI\API\DTO; +namespace AdminKit\Articles\UI\API\Data; use AdminKit\Articles\Models\Article; use Carbon\Carbon; -use Spatie\LaravelData\Concerns\WithDeprecatedCollectionMethod; use Spatie\LaravelData\Data; use Spatie\LaravelData\Lazy; -class ArticleDTO extends Data +class ArticleData extends Data { - use WithDeprecatedCollectionMethod; - public function __construct( public Lazy|int $id, public Lazy|string $slug, @@ -42,14 +39,14 @@ public static function fromModel(Article $article): self Lazy::when(fn () => isset($article->created_at), fn () => $article->created_at), Lazy::when(fn () => isset($article->updated_at), fn () => $article->updated_at), [ - 'title' => $article->seo->title, - 'description' => $article->seo->description, - 'keywords' => $article->seo->keywords, + 'title' => $article->seo?->title, + 'description' => $article->seo?->description, + 'keywords' => $article->seo?->keywords, 'og' => [ - 'url' => $article->seo->og_url, - 'title' => $article->seo->og_title, - 'description' => $article->seo->og_description, - 'image' => $article->seo->getFirstMediaUrl(), + 'url' => $article->seo?->og_url, + 'title' => $article->seo?->og_title, + 'description' => $article->seo?->og_description, + 'image' => $article->seo?->getFirstMediaUrl(), ], ] );