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)。有关更多信息,请参阅 许可文件