From 8168ae2b8d09108449dc4f8c8847cdb426787405 Mon Sep 17 00:00:00 2001 From: sergeybodin Date: Wed, 19 Jul 2023 13:04:12 +0300 Subject: [PATCH] major --- .../Api/Publications/PublicationsController.php | 9 +++++---- app/Services/Forms/Publications/PublicationNewsForms.php | 1 + .../Forms/Publications/PublicationPhotosForms.php | 2 +- app/Transformers/Publications/PublicationTransformer.php | 2 +- 4 files changed, 8 insertions(+), 6 deletions(-) diff --git a/app/Http/Controllers/Api/Publications/PublicationsController.php b/app/Http/Controllers/Api/Publications/PublicationsController.php index 5391949..713d974 100644 --- a/app/Http/Controllers/Api/Publications/PublicationsController.php +++ b/app/Http/Controllers/Api/Publications/PublicationsController.php @@ -28,11 +28,12 @@ class PublicationsController extends Controller { $query = $this->model->query()->orderBy('published_at', 'desc'); $user = Auth::user(); if (!($user->isAdmin ?? null)) $query->where(['is_published' => true]); - if ($page = Page::byUuid($request->get('page_id'))->first()) $query->where(['page_id' => $page->id]); -// if ($page = Page::query()->where(['sub_type' => $request->get('sub_type')])->first()) { -// $query->where('page_id', $page->id); -// } + if ($page = Page::byUuid($request->get('page_id'))->first()) { + $query->where(['page_id' => $page->id]); + } elseif ($page = Page::query()->where(['sub_type' => $request->get('sub_type')])->first()) { + $query->where('page_id', $page->id); + } $paginator = $query->paginate(config('app.pagination_limit')); return fractal($paginator, new PublicationTransformer())->respond(); } diff --git a/app/Services/Forms/Publications/PublicationNewsForms.php b/app/Services/Forms/Publications/PublicationNewsForms.php index 9e3e0ea..c88bbf2 100644 --- a/app/Services/Forms/Publications/PublicationNewsForms.php +++ b/app/Services/Forms/Publications/PublicationNewsForms.php @@ -54,6 +54,7 @@ class PublicationNewsForms extends FormsService { 'name' => 'poster_id', 'title' => 'Превью', 'type' => FieldType::IMAGE, + 'required' => true, 'value' => ($model->poster ?? null) ? fractal($model->poster, new AssetTransformer()) : null ] ]; diff --git a/app/Services/Forms/Publications/PublicationPhotosForms.php b/app/Services/Forms/Publications/PublicationPhotosForms.php index d946c34..6d068e1 100644 --- a/app/Services/Forms/Publications/PublicationPhotosForms.php +++ b/app/Services/Forms/Publications/PublicationPhotosForms.php @@ -33,7 +33,7 @@ class PublicationPhotosForms if (empty($params->assets)) { $assets = []; } else { - $models = Asset::query()->whereIn('uuid', $params->assets)->get(); + $models = Asset::query()->whereIn('uuid', $params->assets)->orderBy('id')->get(); $assets = fractal($models, new AssetTransformer()); } diff --git a/app/Transformers/Publications/PublicationTransformer.php b/app/Transformers/Publications/PublicationTransformer.php index 942f22d..21fc9bd 100644 --- a/app/Transformers/Publications/PublicationTransformer.php +++ b/app/Transformers/Publications/PublicationTransformer.php @@ -44,7 +44,7 @@ class PublicationTransformer extends TransformerAbstract { ]; if ($model->parsedType['name'] === PublicationType::PHOTOS && $params->assets) { - $models = Asset::query()->whereIn('uuid', $params->assets)->get(); + $models = Asset::query()->whereIn('uuid', $params->assets)->orderBy('id')->get(); $result['assets'] = fractal($models, new AssetTransformer()); }