PHPackages                             secretwebmaster/wncms-tags - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. secretwebmaster/wncms-tags

ActiveLibrary

secretwebmaster/wncms-tags
==========================

Add tags and taggable behaviour to your Wncms

v1.7.0(4mo ago)0197↓100%1MITPHPPHP ^8.2

Since Sep 9Pushed 4mo ago1 watchersCompare

[ Source](https://github.com/secretwebmaster/wncms-tags)[ Packagist](https://packagist.org/packages/secretwebmaster/wncms-tags)[ Docs](https://github.com/secretwebmaster/wncms-tags)[ RSS](/packages/secretwebmaster-wncms-tags/feed)WikiDiscussions main Synced today

READMEChangelogDependencies (7)Versions (13)Used By (1)

爲所有 Laravel Eloquent 模型加上 Tag 功能
================================

[](#爲所有-laravel-eloquent-模型加上-tag-功能)

此套件為您的模型提供可標籤行為。安裝完成後，您只需將 `HasTags` trait 添加到 Eloquent 模型，即可使其可標籤。

我們不僅止於一般的標籤功能，WNCMS 標籤包含多種功能。內建支持\[標籤翻譯\]、\[多重標籤類型\]及\[排序功能\]。

以下以 Post 模組爲例：

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

class Post extends Model
{
    use HasTags;

    // ...
}
```

```
// 創建你的模型，以Post為例
$post = Post::create([
   'name' => '文章標題',
]);

// 添加標籤
$post->attachTag('標籤1'); //不指定類型
$post->attachTag('標籤2', '文章標籤'); //指定類型
$post->attachTags(['標籤3', '標籤4']);  //同時創建多個，不指定類型
$post->attachTags(['分類1','分類2'], '文章分類'); //同時創建多個，指定類型，最常用

// 移除標籤
$post->detachTag('標籤1');
$post->detachTag('標籤2', '文章標籤');
$post->detachTags(['標籤3', '標籤4']);
$post->detachTags(['分類1', '分類2'], '文章分類');

// 取得模型的所有標籤
$post->tags;

// 同步標籤
$post->syncTags(['標籤1', '標籤2']); //其他標籤將被移除

// 同步帶有類型的標籤
$post->syncTagsWithType(['標籤1', '標籤2'], '文章標籤');
$post->syncTagsWithType(['紅色', '黑色'], '顏色');

// 獲取帶有類型的標籤
$post->tagsWithType('文章標籤');
$post->tagsWithType('顏色');

// 獲取帶有任意一個標籤的模型
Post::withAnyTags(['標籤1', '標籤2'])->get();

// 獲取帶有所有標籤的模型，需同時擁有所有
Post::withAllTags(['標籤1', '標籤2'])->get();

// 獲取不帶有指定標籤的模型
Post::withoutTags(['標籤1', '標籤2'])->get();

// 翻譯標籤
$tag = Tag::findOrCreate('我的標籤');
$tag->setTranslation('name', 'en', 'My Tag');
$tag->setTranslation('name', 'fr', 'Mon tag');
$tag->setTranslation('name', 'nl', 'Mijn tag');
$tag->save();

// 獲取翻譯
$tag->getTranslation('name'); //返回我的標籤名稱，使用當前語言
$tag->getTranslation('name', 'fr'); //返回 Mon tag (可選語言參數)

// 使用標籤類型
$tag = Tag::findOrCreate('標籤1', '文章標籤');
$tag = Tag::findOrCreate('tag_slug_1'); // slug 不會因語言設定而改變
$tag->slug; //返回 "tag_slug_1"
```

需求
--

[](#需求)

此套件需要 Laravel 8 或更高版本、PHP 8 或更高版本，以及支援 MySQL 相容功能的資料庫。

安裝
--

[](#安裝)

您可以通過 Composer 安裝此套件：

```
composer require secretwebmaster/wncms-tags
```

套件將會自動註冊。

您可以使用以下指令發佈 migrtation 檔案以及 config 配置文件：

```
php artisan vendor:publish --provider="Wncms\Tags\TagsServiceProvider" --tag="tags-migrations"
```

發佈 migrtation 檔案後，您可以通過執行 `migrate` 來創建 `tags` 和 `taggables` 資料表：

```
php artisan migrate
```

###  Health Score

42

—

FairBetter than 90% of packages

Maintenance77

Regular maintenance activity

Popularity13

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity58

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~39 days

Recently: every ~79 days

Total

12

Last Release

128d ago

PHP version history (2 changes)v1.0.0PHP ^8.0

v1.6.2PHP ^8.2

### Community

Maintainers

![](https://www.gravatar.com/avatar/4d0914c464f41d278242ffc0dfe3f4fc3345e57ca0a6c34747f6dd702e7961f3?d=identicon)[secretwebmaster](/maintainers/secretwebmaster)

---

Top Contributors

[![secretwebmaster](https://avatars.githubusercontent.com/u/16463637?v=4)](https://github.com/secretwebmaster "secretwebmaster (22 commits)")

---

Tags

secretwebmasterwncmswncms-tags

###  Code Quality

TestsPest

### Embed Badge

![Health badge](/badges/secretwebmaster-wncms-tags/health.svg)

```
[![Health](https://phpackages.com/badges/secretwebmaster-wncms-tags/health.svg)](https://phpackages.com/packages/secretwebmaster-wncms-tags)
```

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
