Esempio n. 1
0
 protected function findOrCreateTag($tagName)
 {
     $foundTag = Tag::where('tag', $tagName)->first();
     if ($foundTag) {
         return $foundTag;
     }
     return Tag::create(['tag' => $tagName]);
 }
Esempio n. 2
0
 /**
  * @test
  */
 public function given_an_array_of_tag_names_a_post_can_create_new_tags_and_sync_with_given_tags()
 {
     $tag = factory(Tag::class)->create(['tag' => 'mooztag']);
     $post = factory(Post::class)->create();
     $post->setTagsFromArray(['mooztag', 'new tag']);
     $this->assertCount(2, $post->tags);
     $this->assertCount(2, Tag::all());
     $this->seeInDatabase('tags', ['tag' => 'new tag']);
 }