hkp22/laravel-taggable
Composer 安装命令:
composer require hkp22/laravel-taggable
包简介
Laravel model tagging package.
README 文档
README
Laravel Eloquent model tagging package.
Installation
You can install the package via composer:
composer require hkp22/laravel-taggable
Usage
Prepare Taggable model
use Hkp22\LaravelTaggable\Traits\Taggable; use Illuminate\Database\Eloquent\Model as Eloquent; class Lesson extends Eloquent { use Taggable; }
Registering package
Include the service provider within app/config/app.php:
'providers' => [ Hkp22\LaravelTaggable\TaggableServiceProvider::class, ],
Tag Eloquent model
Eg: Tagging a lesson Model.
$lesson->tag(['laravel', 'php']);
or
$tags = $tags = Tag::whereIn('slug', ['laravel', 'testing'])->get(); $lesson->tag($tags);
Un-tag eloquent model
Eg: Un-tagging lesson model.
// Un-tag single tag. $lesson->untag(['laravel']); // Un-tag all tags. $lesson->untag();
Re-tag eloquent model
// Tag $lesson->tag(['laravel', 'testing']); // Re-tag $lesson->retag(['laravel', 'postgres', 'redis']);
Total tagged entities count.
$tag = Tag::first(); $tag->count;
Get model with any given tag
$lessons = Lesson::withAnyTag(['php'])->get();
Get model with only given tag
$lessons = Lesson::withAllTags(['php', 'laravel', 'testing'])->get();
统计信息
- 总下载量: 14
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2018-07-03