- Install the package via composer
composer require balajidharma/laravel-category
- Publish the migration and the config/category.php config file with
php artisan vendor:publish --provider="BalajiDharma\LaravelCategory\CategoryServiceProvider"
- Run the migrations
php artisan migrate
The "Basic Laravel Admin Penel" starter kit come with Laravel Category
use BalajiDharma\LaravelCategory\Models\CategoryType;
CategoryType::create([
'name' => 'Product Category',
'machine_name' => 'product_category',
'description' => 'Site Product Category',
]);
- Get a category tree by using category type id
use BalajiDharma\LaravelCategory\Models\Category;
$items = (new Category)->toTree($type->id);
- Get a category tree by using the category machine name
use BalajiDharma\LaravelCategory\Models\CategoryType;
$items = CategoryType::getCategoryTree('product_category');