PHPackages                             zgldh/laravel-taggable - 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. [Database &amp; ORM](/categories/database)
4. /
5. zgldh/laravel-taggable

ActiveLibrary[Database &amp; ORM](/categories/database)

zgldh/laravel-taggable
======================

Extend from summerblue/laravel-taggable to meed Laravel 5.4 needs.

5.3.0(8y ago)015MITPHPPHP &gt;=5.5.0

Since May 12Pushed 8y ago1 watchersCompare

[ Source](https://github.com/zgldh/laravel-taggable)[ Packagist](https://packagist.org/packages/zgldh/laravel-taggable)[ Docs](https://github.com/summerblue/laravel-taggable)[ RSS](/packages/zgldh-laravel-taggable/feed)WikiDiscussions master Synced yesterday

READMEChangelog (6)Dependencies (8)Versions (9)Used By (0)

Laravel Taggable
================

[](#laravel-taggable)

Introduction
------------

[](#introduction)

Tag support for Laravel Eloquent models using Taggable Trait.

This project extends [rtconner/laravel-tagging](https://github.com/rtconner/laravel-tagging) , add the following feature specially for Chinese User:

- Tag name unique, and using `tag_id` for query data.
- Add [etrepat/baum](https://github.com/etrepat/baum) support complicated tag tree;
- Chinese Pinyin slug support using [overtrue/pinyin](https://github.com/overtrue/pinyin);
- Full test coverage。

> Notice: This projcet only tested and intended only support 5.1 LTS.

❤️ This project is maintained by [@Summer](https://github.com/summerblue), member of [The EST Group](http://estgroupe.com).

中文文档和讨论请见这里：

Baum Nested Sets
----------------

[](#baum-nested-sets)

Integarated [etrepat/baum](https://github.com/etrepat/baum), what is Nested Sets?

> A nested set is a smart way to implement an ordered tree that allows for fast, non-recursive queries. For example, you can fetch all descendants of a node in a single query, no matter how deep the tree.

```
$root = Tag::create(['name' => 'Root']);

// Create Child Tag
$child1 = $root->children()->create(['name' => 'Child1']);

$child = Tag::create(['name' => 'Child2']);
$child->makeChildOf($root);

// Batch create Tag Tree
$tagTree = [
	'name' => 'RootTag',
	'children' => [
		['name' => 'L1Child1',
			'children' => [
				['name' => 'L2Child1'],
				['name' => 'L2Child1'],
				['name' => 'L2Child1'],
			]
		],
		['name' => 'L1Child2'],
		['name' => 'L1Child3'],
	]
];

Tag::buildTree($tagTree);
```

Please refer the Official Project for more advance usage - [etrepat/baum](https://github.com/etrepat/baum)

Tag name rules
--------------

[](#tag-name-rules)

- Any special charactor and empty space will be replace by `-`;
- Automatically smart slug generation, generate Chinese Pinyin slug, fore example: `标签` -&gt; `biao-qian`, will add random value when there is a conflict.

> Tag name normalizer：`$normalize_string = EstGroupe\Taggable\Util::tagName($name)`。

```
Tag::create(['标签名']);
// name: 标签名
// slug: biao-qian-ming

Tag::create(['表签名']);
// name: 表签名
// slug: biao-qian-ming-3243 （3243 is random string）

Tag::create(['标签 名']);
// name: 标签-名
// slug: biao-qian-ming

Tag::create(['标签!名']);
// name: 标签-名
// slug: biao-qian-ming

```

Installation：
-------------

[](#installation)

### Composer install package

[](#composer-install-package)

```
composer require estgroupe/laravel-taggable "5.1.*"
```

### Config and Migration

[](#config-and-migration)

Change `providers` array at `config/app.php`:

```
'providers' => array(
	\EstGroupe\Taggable\Providers\TaggingServiceProvider::class,
);
```

```
php artisan vendor:publish --provider="EstGroupe\Taggable\Providers\TaggingServiceProvider"
php artisan migrate
```

> Please take a close look at file: `config/taggable.php`

### Create your own Tag.php

[](#create-your-own-tagphp)

It's optional but suggested to use your own `Tag` Model:

```
