topkee / tags
为您的Laravel应用添加标签和可标记行为
Requires
- php: ^8.0
- laravel/framework: ^8.12
Requires (Dev)
- orchestra/testbench: ^6.13
- phpunit/phpunit: ^9.5.2
This package is auto-updated.
Last update: 2024-09-28 11:07:27 UTC
README
laravel标签插件,主要是用于做服务实例的二次隔离 源链接https://github.com/Reex11/laravel-tags/tree/disable-translations-v4
这是一个从Spatie/laravel-tags分支出来的版本,以移除翻译功能,因为许多人需要这个功能。
README
此包为您的模型提供可标记行为。安装此包后,您只需将HasTags
特质添加到Eloquent模型中,使其可标记。
但我们并没有停止在每款包中都能找到的常规标签功能。Laravel Tags自带电池。它开箱即支持标签翻译、多个标签类型和排序功能。
您可以在https://spatie.be/docs/laravel-tags上找到文档。
以下是一些代码示例
// create a model with some tags $newsItem = NewsItem::create([ 'name' => 'The Article Title', 'tags' => ['first tag', 'second tag'], //tags will be created if they don't exist ]); // attaching tags $newsItem->attachTag('third tag'); $newsItem->attachTag('third tag','some_type'); $newsItem->attachTags(['fourth tag', 'fifth tag']); $newsItem->attachTags(['fourth_tag','fifth_tag'],'some_type'); // detaching tags $newsItem->detachTags('third tag'); $newsItem->detachTags('third tag','some_type'); $newsItem->detachTags(['fourth tag', 'fifth tag']); $newsItem->detachTags(['fourth tag', 'fifth tag'],'some_type'); // syncing tags $newsItem->syncTags(['first tag', 'second tag']); // all other tags on this model will be detached // syncing tags with a type $newsItem->syncTagsWithType(['category 1', 'category 2'], 'categories'); $newsItem->syncTagsWithType(['topic 1', 'topic 2'], 'topics'); // retrieving tags with a type $newsItem->tagsWithType('categories'); $newsItem->tagsWithType('topics'); // retrieving models that have any of the given tags NewsItem::withAnyTags(['first tag', 'second tag'])->get(); // retrieve models that have all of the given tags NewsItem::withAllTags(['first tag', 'second tag'])->get(); // translating a tag $tag = Tag::findOrCreate('my tag'); $tag->setTranslation('name', 'fr', 'mon tag'); $tag->setTranslation('name', 'nl', 'mijn tag'); $tag->save(); // getting translations $tag->translate('name'); //returns my name $tag->translate('name', 'fr'); //returns mon tag (optional locale param) // convenient translations through taggable models $newsItem->tagsTranslated();// returns tags with slug_translated and name_translated properties $newsItem->tagsTranslated('fr');// returns tags with slug_translated and name_translated properties set for specified locale // using tag types $tag = Tag::findOrCreate('tag 1', 'my type'); // tags have slugs $tag = Tag::findOrCreate('yet another tag'); $tag->slug; //returns "yet-another-tag" // tags are sortable $tag = Tag::findOrCreate('my tag'); $tag->order_column; //returns 1 $tag2 = Tag::findOrCreate('another tag'); $tag2->order_column; //returns 2 // manipulating the order of tags $tag->swapOrder($anotherTag);
Spatie是一家位于比利时安特卫普的网页设计公司。您可以在我们的网站上找到我们所有开源项目的概述这里。
支持我们
我们投入了大量资源来创建最优秀的开源包。您可以通过购买我们的付费产品之一来支持我们。
我们非常感谢您从您的家乡给我们寄明信片,并说明您使用了哪些我们的包。您可以在我们的联系我们页面上找到我们的地址。我们将所有收到的明信片发布在我们的虚拟明信片墙上。
要求
此包需要Laravel 8或更高版本、PHP 8或更高版本,以及支持json
字段和MySQL兼容函数的数据库。
安装
您可以通过Composer安装此包
composer require topkee/tags
该包将自动注册自己。
您可以使用以下命令发布迁移
php artisan vendor:publish --provider="Topkee\Tags\TagsServiceProvider" --tag="tags-migrations"
发布迁移后,您可以通过运行迁移来创建tags
和taggables
表
php artisan migrate
您还可以使用以下命令发布配置文件
php artisan vendor:publish --provider="Topkee\Tags\TagsServiceProvider" --tag="tags-config"
这是已发布配置文件的内容
return [ /* * The given function generates a URL friendly "slug" from the tag name property before saving it. * Defaults to Str::slug (https://laravel.net.cn/docs/5.8/helpers#method-str-slug) */ 'slugger' => null, ];
文档
您可以在https://spatie.be/docs/laravel-tags/v4上找到文档。
在使用此包时遇到困难?发现了一个错误?您对改进laravel-tags
包有任何一般性问题或建议吗?请随时在GitHub上创建一个问题,我们会尽快处理。
如果您发现了一个安全错误,请发送电子邮件到freek@spatie.be,而不是使用问题跟踪器。
测试
- 将
.env.example
复制到.env
并填写您的数据库凭据。 - 运行
composer test
。
变更日志
请参阅 变更日志 了解最近更改了什么。
贡献
请参阅 贡献指南 了解详情。
安全
如果您发现任何与安全相关的问题,请通过电子邮件 freek@spatie.be 联系我们,而不是使用问题跟踪器。
明信片软件
您可以使用此软件包,但如果它进入您的生产环境,我们非常感谢您从家乡给我们寄一张明信片,并说明您正在使用我们的哪些软件包。
我们的地址是:Spatie,Kruikstraat 22,2018 安特卫普,比利时。
我们将所有收到的明信片 发布在我们的公司网站上。
鸣谢
许可证
MIT 许可证(MIT)。请参阅 许可证文件 了解更多信息。