Download the PHP package zaichaopan/taggable without Composer
On this page you can find all versions of the php package zaichaopan/taggable. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download zaichaopan/taggable
More information about zaichaopan/taggable
Files in zaichaopan/taggable
Package taggable
Short Description A package to make eloquent model taggable
License MIT
Informations about the package taggable
Taggable
This Package is used to make eloquent model taggable. It can be used in laravel 5.5 or higher.
Installation
Usage
- Add tags and taggables table
After you install the package, run migration command to add tags and taggables table
The schemas of these two tables
This packages also provides Tag and Taggable models.
Note:
Please make sure tag name is unique. After you create or update a tag, its slug value will be automatically added or updated based on its name value.
- Add hasTags trait to the model you want to tag.
Let's say you have Activity model and you can give it tag.
The hasTags trait provides the following methods to the model which uses it
tags:
It is used to get all the tags of the model:
tag:
Note:
The tag name provided must be valid (exists in the tags table). If a tag name is invalid, it will be ignored. If a tag has already been given to a model, it will not be given again.
reTag:
It is used to update a model's tag. After calling this method on a model, all its old tags will be moved and only the new tag will remain. If the tag name provided is invalid, it will be ignored. If all the provided tag names are invalid, the model will not be retagged. It will still keep its old tags.
unTag:
It is used to remove a tag or multiple tags from a model. If a given tag name is invalid, it will be ignore. If all the given tag names are invalid, none of the model's tags will be removed.
unTagAll:
It is used to removed all the tags of the model.