Skip to content

Commit 09be895

Browse files
committed
allow the name of a tag to be set by changing the name property
1 parent ccb99ba commit 09be895

File tree

3 files changed

+25
-0
lines changed

3 files changed

+25
-0
lines changed

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

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

5+
## 1.3.5 - 2017-02-13
6+
7+
- allow the name of a tag to be set by changing the name property
8+
59
## 1.3.4 - 2017-02-07
610

711
- fix bug where the same tag would be created multiple times

src/Tag.php

+9
Original file line numberDiff line numberDiff line change
@@ -76,4 +76,13 @@ protected static function findOrCreateFromString(string $name, string $type = nu
7676

7777
return $tag;
7878
}
79+
80+
public function setAttribute($key, $value)
81+
{
82+
if ($key === 'name' && ! is_array($value)) {
83+
return $this->setTranslation($key, app()->getLocale(), $value);
84+
}
85+
86+
return parent::setAttribute($key, $value);
87+
}
7988
}

tests/TagTest.php

+12
Original file line numberDiff line numberDiff line change
@@ -155,4 +155,16 @@ public function it_can_find_or_create_a_tag()
155155

156156
$this->assertEquals('string', $tag2->name);
157157
}
158+
159+
/** @test */
160+
public function its_name_can_be_changed_by_setting_its_name_property_to_a_new_value()
161+
{
162+
$tag = Tag::findOrCreate('my tag');
163+
164+
$tag->name = 'new name';
165+
166+
$tag->save();
167+
168+
$this->assertEquals('new name', $tag->name);
169+
}
158170
}

0 commit comments

Comments
 (0)