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

@ -55,7 +55,7 @@ class SetBudget implements ActionInterface
)->first();
if (!is_null($budget)) {
Log::debug('Will set budget "' . $search . '" (#' . $budget->id . ') on journal #' . $this->journal->id . '.');
$this->journal->budgets()->save($budget);
$this->journal->budgets()->sync([$budget->id]);
} else {
Log::debug('Could not find budget "' . $search . '". Failed.');
}

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;
}

View File

@ -23,10 +23,28 @@
</testsuites>
<filter>
<whitelist>
<directory suffix=".php">app/</directory>
<directory suffix=".php">app/Http</directory>
</whitelist>
<blacklist>
<directory>vendor/</directory>
<directory>app/Console</directory>
<directory>app/Events</directory>
<directory>app/Exceptions</directory>
<directory>app/Generator</directory>
<directory>app/Handlers</directory>
<directory>app/Helpers</directory>
<directory>app/Jobs</directory>
<directory>app/Listeners</directory>
<directory>app/Models</directory>
<directory>app/Policies</directory>
<directory>app/Providers</directory>
<directory>app/Repositories</directory>
<directory>app/Rules</directory>
<directory>app/Sql</directory>
<directory>app/Support</directory>
<directory>app/Validation</directory>
<!-- and other directories, -->
</blacklist>
</filter>