idavoll / tag-module
在AsgardCMS中管理标签
3.6.1
2018-07-02 17:02 UTC
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-09-12 12:41:31 UTC
README
分支 | Travis-ci |
---|---|
master |
一个AsgardCMS模块,可以轻松为任何实体添加标签。
安装
Composer
composer require asgardcms/tag-module
迁移
运行标签模块的迁移
php artisan module:migrate tag
权限
转到管理员角色,并为自己分配标签模块的权限。
用法
您的任何实体都可以附加标签。要启用此功能,您的实体需要实现一个接口,使用一个特质,这样就完成了。
1. 在所需实体上添加接口和特质
您的实体需要实现 Modules\Tag\Contracts\TaggableInterface
接口。
为了使您的实体满足此接口,它需要使用以下特质
Modules\Core\Traits\NamespacedEntity
Modules\Tag\Traits\TaggableTrait
标签按命名空间组织。这是在显示字段时获取特定命名空间标签的方法。如果需要创建标签,它也会为该命名空间创建标签。
默认情况下,TaggableTrait
将使用您实体的完整命名空间。但是,您可以通过在实体上使用静态 $entityNamespace
属性来指定更友好/更短的命名空间。
示例
protected static $entityNamespace = 'asgardcms/media';
2. 定义用于标签的新命名空间
在您的模块服务提供者中,boot()
方法,现在需要添加它将要使用的命名空间。这可以通过使用 TagManager
接口来完成。
$this->app[TagManager::class]->registerNamespace(new File());
有了这个,标签模块就知道了新的命名空间。
3. 在您的视图中显示标签字段
通过使用自定义blade指令,您可以在视图中包含标签字段。
- 第一个参数是要获取标签的命名空间。
- (可选)第二个参数是要获取标签的实体(如果给定实体有标签,则预填充输入)。
- (可选)第三个和最后一个参数可以是一个视图。这将覆盖默认的标签视图及其输入字段。
@tags('asgardcms/media', $file)
4. 存储标签
在您的存储库中,您需要调用 setTags()
方法来持久化实体的标签。
$file->setTags(array_get($data, 'tags'));
这就是如何为您的实体使用标签的全部内容。
便利方法
范围:withTag()
获取所有具有给定标签之一的实体。可选指定搜索操作的列,默认为 slug
列。
示例在您的存储库中
// Get all files with either of the 2 tags $files = $this->file->withTag(['your-first-tag', 'some-other-tag'])->get();
范围:whereTag()
获取所有带有指定标签的实体。可选地指定要执行搜索操作的列,默认为 slug
列。
示例在您的存储库中
// 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()
:获取实体的所有标签
您可以通过使用 allTags()
方法来获取实体的所有标签。
$tags = $file->allTags();