/** * 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); }