public function updateTagsForType(string $type) { collect($this->request->get("{$type}_tags"))->each(function ($name) use($type) { $type = new TagType($type); $tag = Tag::findByNameOrCreate($name, $type); $this->model->tags()->attach($tag); }); }
public function seedRandomTags($amount = 10) { $tags = new Collection(); for ($i = 0; $i < $amount; ++$i) { $tag = Tag::findByNameOrCreate($this->faker->words(2, true), TagType::NEWS_TAG()); $tags->add($tag); } return $tags; }