Skip to content
No description or website provided.
Branch: master
Clone or download
2 authors and faustbrian Update dependency kalnoy/nestedset to v5 (#38)

Co-authored-by: Renovate Bot <>
Latest commit 9067122 Oct 6, 2019

Laravel Categories

Build Status PHP from Packagist Latest Version License


Require this package, with Composer, in the root directory of your project.

$ composer require artisanry/categories

To get started, you'll need to publish the vendor assets and migrate:

php artisan vendor:publish --provider="Artisanry\Categories\CategoriesServiceProvider" && php artisan migrate


Nested Sets

Check lazychaser/laravel-nestedset to learn how to create, update, delete, etc. categories.

Setup a Model


namespace App;

use Artisanry\Categories\Traits\HasCategories;
use Illuminate\Database\Eloquent\Model;

class Post extends Model
    use HasCategories;


Get an array with ids and names of categories (useful for drop-downs)


Attach the Post Model these Categories

$post->syncCategories([Category::find(1), Category::find(2), Category::find(3)]);

Detach the Post Model from these Categories


Detach the Post Model from all Categories and attach it to the new ones

$post->syncCategories([Category::find(1), Category::find(3)]);

Attach the Post Model to the given Category


Detach the Post Model from the given Category


Get all Posts that are attached to the given Category



$ phpunit


If you discover a security vulnerability within this package, please send an e-mail to All security vulnerabilities will be promptly addressed.


This project exists thanks to all the people who contribute.


Mozilla Public License Version 2.0 (MPL-2.0).

You can’t perform that action at this time.