Skip to content

Commit

Permalink
allow collection_id to be null in action
Browse files Browse the repository at this point in the history
  • Loading branch information
SethSharp committed Apr 8, 2024
1 parent be6d3ce commit 535d404
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/Actions/Blogs/UpdateBlogAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,13 @@ public function __invoke(Blog $blog, UpdateBlogRequest $updateBlogRequest): Blog
} else {
$collection = $updateBlogRequest->input('collection_id');

if ($blog->collection_id && $collection !== $blog->collection_id) {
if ($collection !== $blog->collection_id) {
// We are providing a collection_id when one already existed
app(RemoveBlogFromCollectionAction::class)($blog, Collection::whereId($blog->collection_id)->first());
app(AddBlogToCollectionAction::class)($blog, Collection::whereId($collection)->first());

if (! is_null($collection)) {
app(AddBlogToCollectionAction::class)($blog, Collection::whereId($collection)->first());
}
} else if (is_null($blog->collection_id)) {
// We are providing a collection for the first time
app(AddBlogToCollectionAction::class)($blog, Collection::whereId($collection)->first());
Expand Down

0 comments on commit 535d404

Please sign in to comment.