idavoll / tag-module
Tag management in AsgardCMS
Installs: 86 833
Dependents: 16
Suggesters: 0
Security: 0
Stars: 0
Watchers: 2
Forks: 12
Type:asgard-module
Requires
- php: >=7.0.0
- composer/installers: ~1.0
Requires (Dev)
- idavoll/page-module: ~3.0
- orchestra/testbench: 3.5.*
- phpunit/phpunit: ~6.0
- dev-master / 4.0.x-dev
- 3.6.1
- 3.6.0
- 3.5.3
- 3.5.2
- 3.5.1
- 3.5.0
- 3.4.0
- 3.3.0
- 3.2.1
- 3.2.0
- 3.1.1
- 3.1.0
- 3.0.x-dev
- 3.0.3
- 3.0.2
- 3.0.1
- 3.0.0
- 2.6.1
- 2.6.0
- 2.5.2
- 2.5.1
- 2.5.0
- 2.4.0
- 2.3.0
- 2.2.0
- 2.1.0
- 2.0.x-dev
- 2.0.4
- 2.0.3
- 2.0.2
- 2.0.1
- 2.0.0
- dev-dependabot/npm_and_yarn/Themes/Adminlte/axios-0.21.1
- dev-dependabot/npm_and_yarn/Themes/Adminlte/bootstrap-3.4.1
- dev-dependabot/npm_and_yarn/Themes/Adminlte/datatables.net-1.10.22
- dev-dependabot/npm_and_yarn/Themes/Adminlte/datatables.net-1.11.3
- dev-dependabot/npm_and_yarn/Themes/Adminlte/json5-and-less-loader-and-laravel-mix-2.2.2
- dev-dependabot/npm_and_yarn/Themes/Adminlte/lodash-4.17.21
- dev-dependabot/npm_and_yarn/Themes/Adminlte/moment-2.29.2
- dev-dependabot/npm_and_yarn/Themes/Adminlte/moment-2.29.4
- dev-dependabot/npm_and_yarn/Themes/Flatly/bootstrap-3.4.1
- dev-dependabot/npm_and_yarn/Themes/Flatly/debug-and-browser-sync-and-compression-and-express-and-serve-index-2.6.9
- dev-dependabot/npm_and_yarn/Themes/Flatly/engine.io-and-browser-sync-6.2.1
- dev-dependabot/npm_and_yarn/Themes/Flatly/express-and-browser-sync-4.18.2
- dev-dependabot/npm_and_yarn/Themes/Flatly/json5-and-laravel-mix-2.2.2
- dev-dependabot/npm_and_yarn/Themes/Flatly/json5-and-laravel-mix-2.2.3
- dev-dependabot/npm_and_yarn/Themes/Flatly/marked-4.0.10
- dev-dependabot/npm_and_yarn/Themes/Flatly/prismjs-1.23.0
- dev-dependabot/npm_and_yarn/Themes/Flatly/prismjs-1.24.0
- dev-dependabot/npm_and_yarn/Themes/Flatly/prismjs-1.25.0
- dev-dependabot/npm_and_yarn/Themes/Flatly/socket.io-parser-and-browser-sync-4.2.1
- dev-dependabot/npm_and_yarn/Themes/Adminlte/lodash-4.17.19
- dev-dependabot/npm_and_yarn/Themes/Flatly/marked-0.7.0
- dev-dependabot/npm_and_yarn/Themes/Adminlte/jquery-3.5.0
- dev-dependabot/npm_and_yarn/Themes/Flatly/jquery-3.5.0
- dev-dependabot/npm_and_yarn/Themes/Flatly/prismjs-1.21.0
- dev-lawniczek-piotr-3.0
- dev-revert-337-kay899-patch-2
This package is auto-updated.
Last update: 2024-11-12 13:01:44 UTC
README
Branch | Travis-ci |
---|---|
master |
An AsgardCMS module which enabled tagging of any entity with ease.
Installation
Composer
composer require asgardcms/tag-module
Migrations
Run the migrations for the tag module
php artisan module:migrate tag
Permissions
Go to the Admin role, and give yourself the permissions for the Tag Module.
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 & 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
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
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
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
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()
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
You can fetch all the tags for an entity by using the allTags()
method.
$tags = $file->allTags();