amalikov / taggy
适用于 Laravel 的优雅标签包
2.0.0
2020-11-04 06:26 UTC
Requires
- php: ^7.1.3
- illuminate/database: 5.4.*||5.5.*||5.6.*||5.7.*||5.8.*||^6.0||^7.0||^8.0
- illuminate/support: 5.4.*||5.5.*||5.6.*||5.7.*||5.8.*||^6.0||^7.0||^8.0
Requires (Dev)
- orchestra/testbench: ^3.4|^4.0|^5.0|^6.0
- phpunit/phpunit: ~5.0||~6.0||~7.0||~8.0||~9.0
This package is auto-updated.
Last update: 2024-09-09 14:20:37 UTC
README
适用于 Laravel 的优雅标签包
安装
通过 Composer 安装包。
从终端运行 Composer require 命令
composer require amalikov/taggy
对于您来说,最终的步骤是添加包的服务提供者并将包别名。为此,打开您的 config/app.php
文件。
Amalikov\Taggy\TaggyServiceProvider::class
前往您要迁移 tags
和 taggable
表的终端文件夹
php artisan migrate
用法
将 TaggableTrait
特性添加到您想使用 tags
的模型。
use Amalikov\Taggy\TaggableTrait;
class YourEloquentModel extends Model
{
use TaggableTrait;
}
为使用的表创建标签数据,例如在控制器或您想要的位置
use Illuminate\Support\Str;
$tags = Tag::create([
'name' => 'Tag Name',
'slug' => Str::slug('Tag Name')
]);
您只需要传递与模型一起工作的数据
$model = new YourEloquentModel;
$model->title = 'Test';
$model->save();
设置新的标签
您可以像这样设置新的标签
$model->tag(['your_tag_name']);
取消现有标签
您可以取消现有标签
$model->untag(['your_tag_name']);
取消所有标签
$model->untag();
重新标记现有标签
$model->retag(['your_tag_name']);