unisharp/categorizable

1.3.2 2019-11-21 09:03 UTC

This package is auto-updated.

Last update: 2024-09-06 19:35:24 UTC


README

Latest Version on Packagist Software License Build Status Coverage Status Quality Score Total Downloads

这是一个让你对任何事物进行分类的包

安装

通过 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

贡献

请查看 CONTRIBUTINGCODE_OF_CONDUCT 以获取详细信息。

安全性

如果您发现任何安全相关的问题,请通过电子邮件 xing1615@gmail.com 而不是使用问题跟踪器。

致谢

许可协议

MIT 许可协议 (MIT)。请参阅 许可文件 以获取更多信息。