rockbuzz/lara-tags

Tag management

9.0.0 2024-07-28 05:02 UTC

This package is auto-updated.

Last update: 2024-10-28 05:40:58 UTC


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.