Commit 202c5c18 authored by Micheal Mand's avatar Micheal Mand

Use the already provided extraction to get all tags

Also remove usage of magic `whereField` method, since it can’t be properly parsed by the IDE - personal preference.
parent 8014aab4
...@@ -63,7 +63,7 @@ trait TaggableTrait ...@@ -63,7 +63,7 @@ trait TaggableTrait
{ {
$instance = new static; $instance = new static;
return $instance->createTagsModel()->with('translations')->whereNamespace($instance->getEntityClassName()); return self::createTagsModel()->with('translations')->where('namespace', $instance->getEntityClassName());
} }
public function setTags($tags, string $type = 'slug'): bool public function setTags($tags, string $type = 'slug'): bool
...@@ -103,8 +103,7 @@ trait TaggableTrait ...@@ -103,8 +103,7 @@ trait TaggableTrait
public function addTag(string $name) public function addTag(string $name)
{ {
$tag = $this->createTagsModel()->where('namespace', $this->getEntityClassName()) $tag = self::allTags()
->with('translations')
->whereHas('translations', function (Builder $q) use ($name) { ->whereHas('translations', function (Builder $q) use ($name) {
$q->where('slug', $this->generateTagSlug($name)); $q->where('slug', $this->generateTagSlug($name));
})->first(); })->first();
...@@ -140,9 +139,7 @@ trait TaggableTrait ...@@ -140,9 +139,7 @@ trait TaggableTrait
public function removeTag(string $name) public function removeTag(string $name)
{ {
$tag = $this->createTagsModel() $tag = self::allTags()
->where('namespace', $this->getEntityClassName())
->with('translations')
->whereHas('translations', function (Builder $q) use ($name) { ->whereHas('translations', function (Builder $q) use ($name) {
$q->where('slug', $this->generateTagSlug($name)); $q->where('slug', $this->generateTagSlug($name));
})->first(); })->first();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment