It's a package to let you cagorize anything
Via Composer
$ composer require unisharp/categorizable
use UniSharp\Category\Categorizable;
class Post extends Model {
use Categorizable;
}
You can categorize by id, name or mixed array and id won't add duplicate category
$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
It will remove category just like categorize
$post->uncategorize(1);
$post->uncategorize("News");
$post->uncategorize([1, "news"]);
$post->uncategorize(1, "news");
remove all category
$post->decategorize();
it will add category after clean all binding categories
same as $post->decategorize()->categorize(....)
$post->recategorize(1);
$post->recategorize("News");
$post->recategorize([1, "news"]);
$post->recategorize(1, "news");
You can find model which has specify categories it also search all children category
Post::hasCategories('News', 1)->get();
It's same as hasCategories but just find category which you specify
Post::hasStrictCategories('News', 1)->get();
You can find model which has specify categories it also search all children category
Post::hasCategories('News', 1)->get();
Please see CHANGELOG for more information on what has changed recently.
$ composer test
Please see CONTRIBUTING and CODE_OF_CONDUCT for details.
If you discover any security related issues, please email [email protected] instead of using the issue tracker.
The MIT License (MIT). Please see License File for more information.