コード例 #1
0
ファイル: TagTest.php プロジェクト: waavi/tagging
 /**
  * @test
  */
 public function delete_tag()
 {
     $tag = Tag::create(['name' => '9 Ball']);
     $this->assertEquals(1, Tag::count());
     $tag->delete();
     $this->assertEquals(0, Tag::count());
 }
コード例 #2
0
ファイル: TaggableTest.php プロジェクト: waavi/tagging
 /**
  * @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());
 }
コード例 #3
0
ファイル: Taggable.php プロジェクト: waavi/tagging
 /**
  *  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');
 }
コード例 #4
0
ファイル: Tag.php プロジェクト: waavi/tagging
 /**
  *  Mutator for the name attribute
  *
  *  @param  string $value
  *  @return void
  */
 public function setNameAttribute($value)
 {
     $this->attributes['name'] = Tag::normalizeTagName($value);
 }