websystem/tags

为您的Laravel应用程序添加标签和可标签化行为

v0.0.2 2022-07-18 17:51 UTC

This package is auto-updated.

Last update: 2024-09-30 01:59:57 UTC


README

Overview Lara-tags

Latest Version on Packagist MIT Licensed Total Downloads

安装

通过Composer安装此包。

从终端运行Composer require命令

composer require websystem/tags

之后,您需要运行迁移。

php artisan migrate

使用方法

以下是一些代码示例

// apply HasTags trait to a model
use Illuminate\Database\Eloquent\Model;
use Websystem\Tags\HasTags;

class Lesson extends Model
{
    use HasTags;

    // ...
}
// create a model tag
use Illuminate\Support\Str;

$tags = Tag::create([
 'name' => 'Tag Name',
 'slug' => Str::slug('Tag Name')
]);
// create a model lesson ex.
$lesson = Lesson::create([
 'title' => 'Lesson Title',
]);

设置新标签

附加标签

$lesson->tag(['your_tag_name', '...']);

取消标签

移除标签

// detach a tag
$lesson->untag(['your_tag_name', '...']);

// detach all tags
$lesson->untag();

重新标记

重新标记标签

$model->retag(['your_tag_name', '...']);