Skip to content

Commit

Permalink
bail out on translation save if parent save failed
Browse files Browse the repository at this point in the history
  • Loading branch information
acasar committed Mar 16, 2017
1 parent 5c2c431 commit 116c64c
Showing 1 changed file with 3 additions and 7 deletions.
10 changes: 3 additions & 7 deletions src/Translatable.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,7 @@ public static function create(array $attributes = [], $translations = [])
{
$model = new static($attributes);

$model->save();

if(is_array($translations)) {
if($model->save() && is_array($translations)) {
$model->saveTranslations($translations);
}

Expand All @@ -59,11 +57,9 @@ public static function create(array $attributes = [], $translations = [])
*/
public static function createInLocale($locale, array $attributes = [], $translations = [])
{
$model = new static($attributes);

$model->setLocale($locale)->save();
$model = (new static($attributes))->setLocale($locale);

if(is_array($translations)) {
if($model->save() && is_array($translations)) {
$model->saveTranslations($translations);
}

Expand Down

0 comments on commit 116c64c

Please sign in to comment.