diff --git a/app/Http/Controllers/Api/Publications/PublicationsController.php b/app/Http/Controllers/Api/Publications/PublicationsController.php index 2118bc4..26968b8 100644 --- a/app/Http/Controllers/Api/Publications/PublicationsController.php +++ b/app/Http/Controllers/Api/Publications/PublicationsController.php @@ -23,17 +23,10 @@ class PublicationsController extends Controller { } public function index(Request $request): JsonResponse { - $where = ['is_published' => true]; - if (Auth::check()) { - if ($request->has('edit_mode')) { - if ($request->get('edit_mode')==='yes') { - unset($where['is_published']); - } - } - } $query = $this->model->query()->orderBy('id', 'desc'); - if ($page = Page::byUuid($request->get('page'))->first()) $where[] = ['page_id' => $page->id]; - $query->where($where); + $user = Auth::user(); + if (!($user->isAdmin ?? null)) $query->where(['is_published' => true]); + if ($page = Page::byUuid($request->get('page'))->first()) $query->where(['page_id' => $page->id]); $paginator = $query->paginate(config('app.pagination_limit')); return fractal($paginator, new PublicationTransformer())->respond(); } @@ -51,7 +44,7 @@ class PublicationsController extends Controller { public function update(Request $request, $uuid): void { } - public function destroy(Request $request, $uuid) { + public function destroy(Request $request, $uuid): JsonResponse { $model = $this->model->byUuid($uuid)->firstOrFail(); $model->delete(); return response()->json(null, 204); diff --git a/app/Models/Pages/Page.php b/app/Models/Pages/Page.php index 29fc752..1809557 100644 --- a/app/Models/Pages/Page.php +++ b/app/Models/Pages/Page.php @@ -96,22 +96,9 @@ class Page extends Model { public static function byUrl($url) { if ($url = trim($url, '/ ')) { $query = self::query(); - $reduceIndex = 0; - collect(explode('/', $url))->reverse()->values()->each(function($slug, $index) use ($query, &$reduceIndex) { - $exist = self::query()->where(['slug' => $slug])->exists(); - if ($exist) { - if ($slug !== '') { - $currentIndex = $index - $reduceIndex; - $currentIndex ? $query->nthParentSlug($currentIndex, $slug) : $query->bySlug($slug); - } - } else { - $reduceIndex++; - $exist = Publication::query()->where(['slug' => $slug])->exists(); - if ($exist) { - $query->whereHas('publications', function($query) use($slug) { - $query->where(['slug' => $slug]); - }); - } + collect(explode('/', $url))->reverse()->values()->each(function($slug, $index) use ($query) { + if ($slug !== '') { + $index ? $query->nthParentSlug($index, $slug) : $query->bySlug($slug); } }); return $query->first(); diff --git a/app/Models/Publications/Publication.php b/app/Models/Publications/Publication.php index bd90cfb..a03476d 100644 --- a/app/Models/Publications/Publication.php +++ b/app/Models/Publications/Publication.php @@ -28,7 +28,6 @@ class Publication extends Model { 'type', 'name', 'excerpt', - 'description', 'is_published' ]; diff --git a/app/Services/Forms/Publications/PublicationForms.php b/app/Services/Forms/Publications/PublicationForms.php index 453bbb6..a12195c 100644 --- a/app/Services/Forms/Publications/PublicationForms.php +++ b/app/Services/Forms/Publications/PublicationForms.php @@ -41,12 +41,6 @@ class PublicationForms extends FormsService { 'required' => true, 'value' => $model->excerpt ?? null ], - [ - 'name' => 'description', - 'title' => 'Описание', - 'type' => FieldType::HTML, - 'value' => $model->description ?? null - ], [ 'name' => 'poster_id', 'title' => 'Фотография профиля', diff --git a/app/Transformers/Publications/PublicationTransformer.php b/app/Transformers/Publications/PublicationTransformer.php index e795b78..d1f6abe 100644 --- a/app/Transformers/Publications/PublicationTransformer.php +++ b/app/Transformers/Publications/PublicationTransformer.php @@ -30,7 +30,6 @@ class PublicationTransformer extends TransformerAbstract { 'type' => $model->parsedType, 'name' => $model->name, 'excerpt' => $model->excerpt, - 'description' => $model->description, 'is_published' => boolval($model->is_published), 'created_at' => $model->created_at ? $model->created_at->toIso8601String() : null, 'updated_at' => $model->updated_at ? $model->updated_at->toIso8601String() : null