Skip to content

Commit

Permalink
Fix updating
Browse files Browse the repository at this point in the history
  • Loading branch information
acasar committed Nov 5, 2016
1 parent 4427472 commit 5be69c6
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ protected function updateI18n(array $values)
->whereOriginal($this->model->getLocaleKey(), $this->model->getLocale());

if($query->exists()) {
unset($values[$this->model->getLocaleKey()]);
return $query->update($values);
} else {
return $this->insertI18n($values, $this->model->getKey());
Expand Down
16 changes: 16 additions & 0 deletions tests/TestCRUD.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,22 @@ public function testModelCanBeUpdated()
$this->assertEquals('Lorem ipsum', $user->bio);
}

public function testSaveTranslationHelper()
{
User::forceCreate([
'name' => 'John Doe',
'bio' => 'Lorem ipsum'
]);

$user = User::first();
$user->forceSaveTranslation('de', ['bio' => 'Lorem ipsum DE']);
$user->forceSaveTranslation('fr', ['bio' => 'Lorem ipsum FR']);

$this->assertEquals('Lorem ipsum', User::translateInto('en')->first()->bio);
$this->assertEquals('Lorem ipsum DE', User::translateInto('de')->first()->bio);
$this->assertEquals('Lorem ipsum FR', User::translateInto('fr')->first()->bio);
}

public function testWhereTranslated()
{
Post::forceCreate(['title' => 'Title 1']);
Expand Down

0 comments on commit 5be69c6

Please sign in to comment.