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