Skip to content

Commit

Permalink
allow the name of a tag to be set by changing the name property
Browse files Browse the repository at this point in the history
  • Loading branch information
freekmurze committed Feb 13, 2017
1 parent ccb99ba commit 09be895
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 0 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

All Notable changes to `laravel-tags` will be documented in this file

## 1.3.5 - 2017-02-13

- allow the name of a tag to be set by changing the name property

## 1.3.4 - 2017-02-07

- fix bug where the same tag would be created multiple times
Expand Down
9 changes: 9 additions & 0 deletions src/Tag.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,4 +76,13 @@ protected static function findOrCreateFromString(string $name, string $type = nu

return $tag;
}

public function setAttribute($key, $value)
{
if ($key === 'name' && ! is_array($value)) {
return $this->setTranslation($key, app()->getLocale(), $value);
}

return parent::setAttribute($key, $value);
}
}
12 changes: 12 additions & 0 deletions tests/TagTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -155,4 +155,16 @@ public function it_can_find_or_create_a_tag()

$this->assertEquals('string', $tag2->name);
}

/** @test */
public function its_name_can_be_changed_by_setting_its_name_property_to_a_new_value()
{
$tag = Tag::findOrCreate('my tag');

$tag->name = 'new name';

$tag->save();

$this->assertEquals('new name', $tag->name);
}
}

0 comments on commit 09be895

Please sign in to comment.