An Eloquent tagging package for Laravel
Install the package through Composer.
Run the Composer require command from the Terminal:
composer require amalikov/taggy
The final steps for you are to add the service provider of the package and alias the package. To do this open your config/app.php
file.
Amalikov\Taggy\TaggyServiceProvider::class
Go to the terminal in folder that you are migrate the tags
and taggable
tables:
php artisan migrate
Add the TaggableTrait
trait to a model you like to use tags
on.
use Amalikov\Taggy\TaggableTrait;
class YourEloquentModel extends Model
{
use TaggableTrait;
}
Create a tags data for table that you use for example in controller or whatever place you want:
use Illuminate\Support\Str;
$tags = Tag::create([
'name' => 'Tag Name',
'slug' => Str::slug('Tag Name')
]);
You just need to pass the data that working with the models
$model = new YourEloquentModel;
$model->title = 'Test';
$model->save();
You can set a new tags like this:
$model->tag(['your_tag_name']);
You can untag existing tag
$model->untag(['your_tag_name']);
$model->untag();
$model->retag(['your_tag_name']);