major
parent
842b26e659
commit
af8b2f6841
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
|
|
|
|||
|
|
@ -28,7 +28,6 @@ class Publication extends Model {
|
|||
'type',
|
||||
'name',
|
||||
'excerpt',
|
||||
'description',
|
||||
'is_published'
|
||||
];
|
||||
|
||||
|
|
|
|||
|
|
@ -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' => 'Фотография профиля',
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Reference in New Issue