PHPackages                             asgardcms/tag-module - 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. asgardcms/tag-module

ActiveAsgard-module

asgardcms/tag-module
====================

Tag management in AsgardCMS

17045[1 issues](https://github.com/AsgardCms/Tag/issues)PHP

Since Sep 8Pushed 8y ago3 watchersCompare

[ Source](https://github.com/AsgardCms/Tag)[ Packagist](https://packagist.org/packages/asgardcms/tag-module)[ RSS](/packages/asgardcms-tag-module/feed)WikiDiscussions master Synced 2mo ago

READMEChangelogDependenciesVersions (1)Used By (0)

Tag Module
==========

[](#tag-module)

[![Latest Version](https://camo.githubusercontent.com/d28a00d7fba0555890e30a2baec60afbe373e05de9f7ce514cb19013518c925d/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f72656c656173652f617367617264636d732f7461672e7376673f7374796c653d666c61742d737175617265)](https://github.com/asgardcms/tag/releases)[![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE.md)[![Build Status](https://camo.githubusercontent.com/4265385a83b9dc817ae8b052c7b24b743b5e4577d3e10e35288da46336f3910a/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f417367617264436d732f5461672f6d61737465722e7376673f7374796c653d666c61742d737175617265)](https://travis-ci.org/AsgardCms/Tag)[![Scrutinizer Coverage](https://camo.githubusercontent.com/707aba6e9d4346514c6fd1d79c8f6ab6b47dc26838ee4aeed687d011474e18fd/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f636f7665726167652f672f417367617264436d732f5461672e7376673f6d61784167653d3836343030267374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/AsgardCms/Tag/?branch=master)[![Quality block](https://camo.githubusercontent.com/3bd77a6ece41633dfbeaee1f36e5c57c7ae7eef0e2bd0987330680ab9b722b07/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f617367617264636d732f7461672e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/asgardcms/tag)[![SensioLabs Insight](https://camo.githubusercontent.com/3ec5966cabd876c0f0fee834a2bc12564d31eeb267fa58a231969f59f953687e/68747470733a2f2f696d672e736869656c64732e696f2f73656e73696f6c6162732f692f30393139653461612d386536632d343366302d383630642d3736323663646461663439382e737667)](https://insight.sensiolabs.com/projects/0919e4aa-8e6c-43f0-860d-7626cddaf498)

[![Slack](https://camo.githubusercontent.com/5379498bc3498bb41df326f2981e2cae90bd1ba46d635bb0c0faedcdc746278d/687474703a2f2f736c61636b2e617367617264636d732e636f6d2f62616467652e737667)](http://slack.asgardcms.com/)

BranchTravis-cimaster[![Build Status](https://camo.githubusercontent.com/e59db3b9a3d83c532c5c3a71985582c1e8385d835673f3ec9969e7753e7cd5a5/68747470733a2f2f7472617669732d63692e6f72672f417367617264436d732f5461672e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/AsgardCms/Tag)An AsgardCMS module which enabled tagging of any entity with ease.

Installation
------------

[](#installation)

### Composer

[](#composer)

```
composer require asgardcms/tag-module

```

### Migrations

[](#migrations)

Run the migrations for the tag module

```
php artisan module:migrate tag

```

### Permissions

[](#permissions)

Go to the Admin role, and give yourself the permissions for the Tag Module.

Usage
-----

[](#usage)

Any of you entities can have tags attached to it. To enable this your entity needs to implement an interface, use a trait and that's it.

### 1. Add interface &amp; trait on desired entity

[](#1-add-interface--trait-on-desired-entity)

Your entity needs to implement the `Modules\Tag\Contracts\TaggableInterface` interface.

In order for your entity to satisfy this interface it needs to use the following traits:

- `Modules\Core\Traits\NamespacedEntity`
- `Modules\Tag\Traits\TaggableTrait`

Tags are organised by namespace. This is used in order to get the tags for a specific namespace on the display of the field. It also creates tags for that namespace if tags need to be created.

By default the `TaggableTrait` will use the full namespace of your entity. However, you can specify a nicer / shorter namespace to use by using the static `$entityNamespace` property on your entity.

Example:

```
protected static $entityNamespace = 'asgardcms/media';
```

### 2. Defining a new namespace to use for tags

[](#2-defining-a-new-namespace-to-use-for-tags)

In your module Service Provider, `boot()` method, you now need to add the namespace it's going to use. This can be done using the `TagManager` interface.

```
$this->app[TagManager::class]->registerNamespace(new File());
```

And with this, the Tag Module is aware of the new namespace.

### 3. Display the tag field on your views

[](#3-display-the-tag-field-on-your-views)

By using a custom blade directive you can include the tags field on your views.

- The first argument is the namespace to get the tags for.
- (optional) Second argument is the entity to fetch the tags for (pre-filling the input if tags are present for given entity).
- (optional) Third and last argument can be a view to use. This will override the default tags view with its input field.

```
@tags('asgardcms/media', $file)
```

### 4. Store tags

[](#4-store-tags)

In your repositories you need to call the `setTags()` method to persist the tags on your entity.

```
$file->setTags(array_get($data, 'tags'));
```

And that's all on how to use tags for your entities.

Convenience methods
-------------------

[](#convenience-methods)

### Scope: `withTag()`

[](#scope-withtag)

Get all the entities with one of the given tag(s). Optionally specify the column on which to perform the search operation, defaults to the `slug` column.

Example in your repository :

```
// Get all files with either of the 2 tags
$files = $this->file->withTag(['your-first-tag', 'some-other-tag'])->get();
```

### Scope: `whereTag()`

[](#scope-wheretag)

Get all the entities with the given tag(s). Optionally specify the column on which to perform the search operation, defaults to `slug` column.

Example in your repository :

```
// Get all files with all given tags
$files = $this->file->whereTag(['your-first-tag', 'some-other-tag'])->get();

// Get all files with the given tag
$files = $this->file->whereTag('your-first-tag')->get();
```

### `allTags()`: Get all the tags for the entity

[](#alltags-get-all-the-tags-for-the-entity)

You can fetch all the tags for an entity by using the `allTags()` method.

```
$tags = $file->allTags();
```

###  Health Score

20

—

LowBetter than 14% of packages

Maintenance0

Infrequent updates — may be unmaintained

Popularity18

Limited adoption so far

Community13

Small or concentrated contributor base

Maturity41

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 98.7% 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.

### Community

Maintainers

![](https://www.gravatar.com/avatar/565946b8d70f5fa172a21f87b7f0e3abdce0611cc1cd300ec8e7b360bdb0a4bc?d=identicon)[nWidart](/maintainers/nWidart)

---

Top Contributors

[![nWidart](https://avatars.githubusercontent.com/u/882397?v=4)](https://github.com/nWidart "nWidart (75 commits)")[![motchju](https://avatars.githubusercontent.com/u/3864824?v=4)](https://github.com/motchju "motchju (1 commits)")

### Embed Badge

![Health badge](/badges/asgardcms-tag-module/health.svg)

```
[![Health](https://phpackages.com/badges/asgardcms-tag-module/health.svg)](https://phpackages.com/packages/asgardcms-tag-module)
```

PHPackages © 2026

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