websystem / tags
Add tags and taggable behaviour to your Laravel app
Fund package maintenance!
WebSystem-studio
friend
Requires
- php: ^8.0
- laravel/framework: ^8.67|^9.0
Requires (Dev)
- orchestra/testbench: ^7.6
- phpunit/phpunit: ^9.5.10
This package is auto-updated.
Last update: 2025-05-29 01:56:22 UTC
README
Installation
Install the package through Composer.
Run the Composer require command from the Terminal:
composer require websystem/tags
After that, you need to run migrations.
php artisan migrate
Usage
Here are some code examples:
// apply HasTags trait to a model use Illuminate\Database\Eloquent\Model; use Websystem\Tags\HasTags; class Lesson extends Model { use HasTags; // ... }
// create a model tag use Illuminate\Support\Str; $tags = Tag::create([ 'name' => 'Tag Name', 'slug' => Str::slug('Tag Name') ]);
// create a model lesson ex. $lesson = Lesson::create([ 'title' => 'Lesson Title', ]);
Set a new tags
Attaching tags
$lesson->tag(['your_tag_name', '...']);
Untag
Detaching tags
// detach a tag $lesson->untag(['your_tag_name', '...']); // detach all tags $lesson->untag();
Retag
Retaging tags
$model->retag(['your_tag_name', '...']);