major
parent
842b26e659
commit
af8b2f6841
|
|
@ -23,17 +23,10 @@ class PublicationsController extends Controller {
|
||||||
}
|
}
|
||||||
|
|
||||||
public function index(Request $request): JsonResponse {
|
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');
|
$query = $this->model->query()->orderBy('id', 'desc');
|
||||||
if ($page = Page::byUuid($request->get('page'))->first()) $where[] = ['page_id' => $page->id];
|
$user = Auth::user();
|
||||||
$query->where($where);
|
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'));
|
$paginator = $query->paginate(config('app.pagination_limit'));
|
||||||
return fractal($paginator, new PublicationTransformer())->respond();
|
return fractal($paginator, new PublicationTransformer())->respond();
|
||||||
}
|
}
|
||||||
|
|
@ -51,7 +44,7 @@ class PublicationsController extends Controller {
|
||||||
public function update(Request $request, $uuid): void {
|
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 = $this->model->byUuid($uuid)->firstOrFail();
|
||||||
$model->delete();
|
$model->delete();
|
||||||
return response()->json(null, 204);
|
return response()->json(null, 204);
|
||||||
|
|
|
||||||
|
|
@ -96,22 +96,9 @@ class Page extends Model {
|
||||||
public static function byUrl($url) {
|
public static function byUrl($url) {
|
||||||
if ($url = trim($url, '/ ')) {
|
if ($url = trim($url, '/ ')) {
|
||||||
$query = self::query();
|
$query = self::query();
|
||||||
$reduceIndex = 0;
|
collect(explode('/', $url))->reverse()->values()->each(function($slug, $index) use ($query) {
|
||||||
collect(explode('/', $url))->reverse()->values()->each(function($slug, $index) use ($query, &$reduceIndex) {
|
|
||||||
$exist = self::query()->where(['slug' => $slug])->exists();
|
|
||||||
if ($exist) {
|
|
||||||
if ($slug !== '') {
|
if ($slug !== '') {
|
||||||
$currentIndex = $index - $reduceIndex;
|
$index ? $query->nthParentSlug($index, $slug) : $query->bySlug($slug);
|
||||||
$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]);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
return $query->first();
|
return $query->first();
|
||||||
|
|
|
||||||
|
|
@ -28,7 +28,6 @@ class Publication extends Model {
|
||||||
'type',
|
'type',
|
||||||
'name',
|
'name',
|
||||||
'excerpt',
|
'excerpt',
|
||||||
'description',
|
|
||||||
'is_published'
|
'is_published'
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -41,12 +41,6 @@ class PublicationForms extends FormsService {
|
||||||
'required' => true,
|
'required' => true,
|
||||||
'value' => $model->excerpt ?? null
|
'value' => $model->excerpt ?? null
|
||||||
],
|
],
|
||||||
[
|
|
||||||
'name' => 'description',
|
|
||||||
'title' => 'Описание',
|
|
||||||
'type' => FieldType::HTML,
|
|
||||||
'value' => $model->description ?? null
|
|
||||||
],
|
|
||||||
[
|
[
|
||||||
'name' => 'poster_id',
|
'name' => 'poster_id',
|
||||||
'title' => 'Фотография профиля',
|
'title' => 'Фотография профиля',
|
||||||
|
|
|
||||||
|
|
@ -30,7 +30,6 @@ class PublicationTransformer extends TransformerAbstract {
|
||||||
'type' => $model->parsedType,
|
'type' => $model->parsedType,
|
||||||
'name' => $model->name,
|
'name' => $model->name,
|
||||||
'excerpt' => $model->excerpt,
|
'excerpt' => $model->excerpt,
|
||||||
'description' => $model->description,
|
|
||||||
'is_published' => boolval($model->is_published),
|
'is_published' => boolval($model->is_published),
|
||||||
'created_at' => $model->created_at ? $model->created_at->toIso8601String() : null,
|
'created_at' => $model->created_at ? $model->created_at->toIso8601String() : null,
|
||||||
'updated_at' => $model->updated_at ? $model->updated_at->toIso8601String() : null
|
'updated_at' => $model->updated_at ? $model->updated_at->toIso8601String() : null
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue