Skip to content

Commit 535d404

Browse files
committed
allow collection_id to be null in action
1 parent be6d3ce commit 535d404

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

src/Actions/Blogs/UpdateBlogAction.php

+5-2
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,13 @@ public function __invoke(Blog $blog, UpdateBlogRequest $updateBlogRequest): Blog
4545
} else {
4646
$collection = $updateBlogRequest->input('collection_id');
4747

48-
if ($blog->collection_id && $collection !== $blog->collection_id) {
48+
if ($collection !== $blog->collection_id) {
4949
// We are providing a collection_id when one already existed
5050
app(RemoveBlogFromCollectionAction::class)($blog, Collection::whereId($blog->collection_id)->first());
51-
app(AddBlogToCollectionAction::class)($blog, Collection::whereId($collection)->first());
51+
52+
if (! is_null($collection)) {
53+
app(AddBlogToCollectionAction::class)($blog, Collection::whereId($collection)->first());
54+
}
5255
} else if (is_null($blog->collection_id)) {
5356
// We are providing a collection for the first time
5457
app(AddBlogToCollectionAction::class)($blog, Collection::whereId($collection)->first());

0 commit comments

Comments
 (0)