rockbuzz / lara-tags
Tag management
Installs: 2 339
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 2
Forks: 0
Open Issues: 0
Requires
- php: >=8.1
- spatie/laravel-sluggable: ^3.0
Requires (Dev)
- orchestra/testbench: ^7.0
- squizlabs/php_codesniffer: ^3.0
README
Tag management
Requirements
PHP >=7.3
Install
$ composer require rockbuzz/lara-tags
$ php artisan vendor:publish --provider="Rockbuzz\LaraTags\ServiceProvider" --tag="migrations"
$ php artisan migrate
Add the Taggable
trait to the template for which you will have tags
use Rockbuzz\LaraTags\Traits\Taggable; class Article extends Model { use Taggable; }
Usage
use Rockbuzz\LaraTags\Models\Tag; $tag = Tag::findFromSlug('slug'); //instance or null $tag = Tag::findFromSlug('slug', 'type'); //instance or null
$article = new Article(); $article->tags(); //MorphToMany $article->tags; //Collection $article->tagsWithType('type'); //Collection $article->hasTag('tag_name'); //boolean $article->hasTag($tagInstance); //boolean
Scopes
Article::withAnyTags($arrayTags); Article::withAnyTags($arrayTags, 'type');
or
Article::withAnyTags($arrayIdTags); Article::withAnyTags($arrayIdTags, 'type');
or
Article::withAnyTags($arrayNameTags); Article::withAnyTags($arrayNameTags, 'type');
License
The Lara Tags is open-sourced software licensed under the MIT license.