rockbuzz/lara-tags

Tag management

1.0.1 2021-09-01 13:02 UTC

This package is auto-updated.

Last update: 2022-06-29 01:59:48 UTC


README

Tag management

badge.svg

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.