The Vhnh Taggable package allows to tag your Eloquent models.
Tags are provided via a polymorphic many-to-many relationship. To setup the relationship you may want to use the Vhnh\Taggable\Taggable
trait.
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
use Vhnh\Taggable\Taggable;
class BlogPost extends Model
{
use Taggable;
}
This traits methods return a Illuminate\Database\Eloquent\Relations\Relation
instance which forward calls to Illuminate\Database\Eloquent\Builder
.
From a Vhnh\Taggable\Tag
instance you may use the taggables
method which also returns a Illuminate\Database\Eloquent\Relations\Relation
instance.
Tag::fromName('recipe')->taggables(BlogPost::class)->get();
However, the Vhnh\Taggable\Taggable
trait also provides a static whereTag
method.
BlogPost::whereTag('recipe')->get();
The Vhnh Bookmark package is open-sourced software licensed under the MIT license.