rockbuzz/lara-tags

Tag management

3.0.1 2023-08-25 11:28 UTC

This package is auto-updated.

Last update: 2024-03-25 12:39:55 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.