app-ark/laravel-tags
Composer 安装命令:
composer require app-ark/laravel-tags
包简介
Add tags and taggable behaviour to your Laravel app
关键字:
README 文档
README
This package offers taggable behaviour for your models. After the package is installed the only thing you have to do is add the HasTags trait to an Eloquent model to make it taggable.
But we didn't stop with the regular tagging capabilities you find in every package. Laravel Tags comes with batteries included. Out of the box it has support for translating tags, multiple tag types and sorting capabilities.
You'll find the documentation on https://docs.spatie.be/laravel-tags/v2.
Here are some code examples:
//create a model with some tags $newsItem = NewsItem::create([ 'name' => 'testModel', 'tags' => ['tag', 'tag2'], //tags will be created if they don't exist ]); //attaching tags $newsItem->attachTag('tag3'); $newsItem->attachTags(['tag4', 'tag5']); //detaching tags $newsItem->detachTags('tag3'); $newsItem->detachTags(['tag4', 'tag5']); //syncing tags $newsItem->syncTags(['tag1', 'tag2']); // all other tags on this model will be detached //syncing tags with a type $newsItem->syncTagsWithType(['tag1', 'tag2'], 'typeA'); $newsItem->syncTagsWithType(['tag1', 'tag2'], 'typeB'); //retrieving tags with a type $newsItem->tagsWithType('typeA'); $newsItem->tagsWithType('typeB'); //retrieving models that have any of the given tags NewsItem::withAnyTags(['tag1', 'tag2'])->get(); //retrieve models that have all of the given tags NewsItem::withAllTags(['tag1', 'tag2'])->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 is a webdesign agency based in Antwerp, Belgium. You'll find an overview of all our open source projects on our website.
Requirements
This package requires Laravel 5.8 or higher, PHP 7.2 or higher and a database that supports json fields and functions such as MySQL 5.7 or higher.
Installation
You can install the package via composer:
composer require spatie/laravel-tags
The package will automatically register itself.
You can publish the migration with:
php artisan vendor:publish --provider="Spatie\Tags\TagsServiceProvider" --tag="migrations"
After the migration has been published you can create the tags and taggables tables by running the migrations:
php artisan migrate
You can optionally publish the config file with:
php artisan vendor:publish --provider="Spatie\Tags\TagsServiceProvider" --tag="config"
This is the contents of the published config file:
return [ /* * The given function generates a URL friendly "slug" from the tag name property before saving it. * Defaults to Str::slug (https://laravel.com/docs/5.8/helpers#method-str-slug) */ 'slugger' => null, ];
Documentation
You'll find the documentation on https://docs.spatie.be/laravel-tags/v2.
Find yourself stuck using the package? Found a bug? Do you have general questions or suggestions for improving the laravel-tags package? Feel free to create an issue on GitHub, we'll try to address it as soon as possible.
If you've found a bug regarding security please mail freek@spatie.be instead of using the issue tracker.
Testing
- Copy
.env.exampleto.envand fill in your database credentials. - Run
composer test.
Changelog
Please see CHANGELOG for more information what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security
If you discover any security related issues, please email freek@spatie.be instead of using the issue tracker.
Postcardware
You're free to use this package, but if it makes it to your production environment we highly appreciate you sending us a postcard from your hometown, mentioning which of our package(s) you are using.
Our address is: Spatie, Samberstraat 69D, 2060 Antwerp, Belgium.
We publish all received postcards on our company website.
Credits
Support us
Spatie is a webdesign agency based in Antwerp, Belgium. You'll find an overview of all our open source projects on our website.
Does your business depend on our contributions? Reach out and support us on Patreon. All pledges will be dedicated to allocating workforce on maintenance and new awesome stuff.
License
The MIT License (MIT). Please see License File for more information.
app-ark/laravel-tags 适用场景与选型建议
app-ark/laravel-tags 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 183 次下载、GitHub Stars 达 0, 最近一次更新时间为 2019 年 07 月 11 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「spatie」 「laravel-tags」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 app-ark/laravel-tags 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 app-ark/laravel-tags 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 app-ark/laravel-tags 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Add tags and taggable behaviour to your Laravel app
Receive webhooks in Laravel apps
Add tags and taggable behaviour to your Laravel app For MongoDB
Easily optimize images using PHP
Store your application settings
Speed up a Laravel application by caching the entire response additions
统计信息
- 总下载量: 183
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 3
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2019-07-11