Get all tags related to taggable class #415
reesmcivor
started this conversation in
Ideas
Replies: 2 comments
-
I'm looking for this too. Did you find any better way to do this? |
Beta Was this translation helpful? Give feedback.
0 replies
-
In my case, what I need is to get tags that have relation with any model. Here is what I do:
class Tag extends \Spatie\Tags\Tag
{
use HasUuids;
public function courses(): \Illuminate\Database\Eloquent\Relations\MorphToMany
{
return $this->morphedByMany(Course::class, 'taggable');
}
} |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi there,
I can't find this currently in any discussions. Apologies if it has been covered before.
I'm creating a search type functionality that includes listing all the tags in a select dropdown field but I couldn't find a method to get all tags using a specific taggable model. So I have come up with the following:
Tag::query()->join('taggables', 'taggables.tag_id', '=', 'tags.id')->where('taggable_type', '=', Exercise::class)>get();
It works fine but I just want to be sure there isn't anything out there already that I am missing from the current package.
Beta Was this translation helpful? Give feedback.
All reactions