This prevents constraint errors when the specified category has already been set.

This commit is contained in:
James Cole
2016-01-23 16:48:15 +01:00
parent 664fde2344
commit 99d14e8cbe
3 changed files with 21 additions and 3 deletions

View File

@@ -47,7 +47,7 @@ class SetCategory implements ActionInterface
$name = $this->action->action_value;
$category = Category::firstOrCreateEncrypted(['name' => $name, 'user_id' => Auth::user()->id]);
Log::debug('Will set category "' . $name . '" (#' . $category->id . ') on journal #' . $this->journal->id . '.');
$this->journal->categories()->save($category);
$this->journal->categories()->sync([$category->id]);
return true;
}