diff --git a/app/Http/Controllers/CollectionController.php b/app/Http/Controllers/CollectionController.php index 588340a35..4fc7dfe65 100644 --- a/app/Http/Controllers/CollectionController.php +++ b/app/Http/Controllers/CollectionController.php @@ -205,4 +205,36 @@ class CollectionController extends Controller ]; }); } + + public function deleteId(Request $request) + { + $this->validate($request, [ + 'collection_id' => 'required|int|min:1|exists:collections,id', + 'post_id' => 'required|int|min:1|exists:statuses,id' + ]); + + $profileId = Auth::user()->profile_id; + $collectionId = $request->input('collection_id'); + $postId = $request->input('post_id'); + + $collection = Collection::whereProfileId($profileId)->findOrFail($collectionId); + $count = $collection->items()->count(); + + if($count == 1) { + abort(400, 'You cannot delete the only post of a collection!'); + } + + $status = Status::whereScope('public') + ->whereIn('type', ['photo', 'photo:album', 'video']) + ->findOrFail($postId); + + $item = CollectionItem::whereCollectionId($collection->id) + ->whereObjectType('App\Status') + ->whereObjectId($status->id) + ->firstOrFail(); + + $item->delete(); + + return 200; + } } diff --git a/public/js/collections.js b/public/js/collections.js index 1d1498c92..7bba7df6d 100644 Binary files a/public/js/collections.js and b/public/js/collections.js differ diff --git a/public/mix-manifest.json b/public/mix-manifest.json index f0ac4d11b..cc4135fe0 100644 Binary files a/public/mix-manifest.json and b/public/mix-manifest.json differ diff --git a/resources/assets/js/components/CollectionComponent.vue b/resources/assets/js/components/CollectionComponent.vue index bf7c4b58f..18d6ccf5b 100644 --- a/resources/assets/js/components/CollectionComponent.vue +++ b/resources/assets/js/components/CollectionComponent.vue @@ -15,7 +15,7 @@
-