unisharp / categorizable
分类模型
1.3.2
2019-11-21 09:03 UTC
Requires
- php: ^7.0
- illuminate/config: >=5.5.0
- illuminate/database: >=5.5.0
- illuminate/support: >=5.5.0
- kalnoy/nestedset: ^5.0
Requires (Dev)
- codedungeon/phpunit-result-printer: ^0.4.4 || ^0.26.0
- friendsofphp/php-cs-fixer: ^1.11 || ^2.0.0
- mockery/mockery: ^0.9.4 || ^1.0.0
- orchestra/database: ~3.5.0 || ~4.0.0
- orchestra/testbench: ~3.5.0 || ~4.0.0
- phpunit/phpunit: ^6.2 || ^7.0|^8.0
- scrutinizer/ocular: ^1.3
- squizlabs/php_codesniffer: 3.*
README
这是一个让你对任何事物进行分类的包
安装
通过 Composer
$ composer require unisharp/categorizable
用法
use UniSharp\Category\Categorizable; class Post extends Model { use Categorizable; }
分类
你可以通过 id、名称或混合数组进行分类,并且 id 不会添加重复的分类
$post->categorize(1); // by category id, it will do nothing if it can't find this category $post->categorize("News"); // by category name and it will create new one if it can't find category $post->categorize([1, "news"]); // You can use array $post->categorize(1, "news"); // it's same as using array
取消分类
它将像分类一样移除分类
$post->uncategorize(1); $post->uncategorize("News"); $post->uncategorize([1, "news"]); $post->uncategorize(1, "news");
递归取消分类
移除所有分类
$post->decategorize();
重新分类
在清理所有绑定分类后添加分类
等同于 $post->decategorize()->categorize(....)
$post->recategorize(1); $post->recategorize("News"); $post->recategorize([1, "news"]); $post->recategorize(1, "news");
hasCategories
你可以找到具有指定分类的模型,它还会搜索所有子分类
Post::hasCategories('News', 1)->get();
hasStrictCategories
它与 hasCategories 相同,但仅查找你指定的分类
Post::hasStrictCategories('News', 1)->get();
你可以找到具有指定分类的模型,它还会搜索所有子分类
Post::hasCategories('News', 1)->get();
变更日志
请查看 CHANGELOG 以获取更多最近更改的信息。
测试
$ composer test
贡献
请查看 CONTRIBUTING 和 CODE_OF_CONDUCT 以获取详细信息。
安全性
如果您发现任何安全相关的问题,请通过电子邮件 xing1615@gmail.com 而不是使用问题跟踪器。
致谢
许可协议
MIT 许可协议 (MIT)。请参阅 许可文件 以获取更多信息。