/** * @test */ public function delete_tag() { $tag = Tag::create(['name' => '9 Ball']); $this->assertEquals(1, Tag::count()); $tag->delete(); $this->assertEquals(0, Tag::count()); }
/** * @test */ public function add_new_tag() { $this->post->tag('new TaG'); $this->assertEquals('new tag', $this->post->tagNames); $this->assertEquals(['new tag'], $this->post->tagArray); $this->assertEquals(1, $this->post->tags->count()); $this->assertEquals(4, Tag::count()); }
/** * Removes the given tags from the model. * * @param mixed $tagNames Array or comma separated list of tags to apply to the model. */ public function untag($tagNames) { $tagNames = collect(is_array($tagNames) ? $tagNames : explode(',', $tagNames))->map(function ($tagName) { return Tag::normalizeTagName($tagName); })->toArray(); $tags = app(TagInterface::class)->whereIn('name', $tagNames)->get()->pluck('id')->toArray(); $this->tags()->detach($tags); return $this->load('tags'); }
/** * Mutator for the name attribute * * @param string $value * @return void */ public function setNameAttribute($value) { $this->attributes['name'] = Tag::normalizeTagName($value); }