rockbuzz/lara-tags

标签管理

9.0.0 2024-07-28 05:02 UTC

This package is auto-updated.

Last update: 2024-09-28 05:31:01 UTC


README

标签管理

要求

PHP >=7.3

安装

$ composer require rockbuzz/lara-tags
$ php artisan vendor:publish --provider="Rockbuzz\LaraTags\ServiceProvider" --tag="migrations"
$ php artisan migrate

Taggable 特性添加到需要标签的模板中

use Rockbuzz\LaraTags\Traits\Taggable;

class Article extends Model
{
    use Taggable;
}

用法

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

作用域

Article::withAnyTags($arrayTags);
Article::withAnyTags($arrayTags, 'type');

或者

Article::withAnyTags($arrayIdTags);
Article::withAnyTags($arrayIdTags, 'type');

或者

Article::withAnyTags($arrayNameTags);
Article::withAnyTags($arrayNameTags, 'type');

许可证

Lara Tags 是开源软件,遵循 MIT 许可协议