PHP code example of laravel-enso / categories

1. Go to this page and download the library: Download laravel-enso/categories library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

laravel-enso / categories example snippets


use LaravelEnso\Categories\Models\Category;

$category = Category::create([
    'name' => 'Solar Panels',
    'is_featured' => true,
]);

$subcategory = Category::create([
    'name' => 'Monocrystalline',
    'parent_id' => $category->id,
    'is_featured' => false,
    'order_index' => Category::nextIndex($category->id),
]);

$subcategory->move(orderIndex: 1, parentId: null);

$tree = Category::tree();

$level = $subcategory->level();
$depth = $category->depth();
$parentTree = $subcategory->parentTree();
$flattenedIds = $category->flattenCurrentAndBelowIds();

$options = Category::with('recursiveParent')
    ->get()
    ->map
    ->label();
bash
php artisan migrate
bash
php artisan vendor:publish --tag=categories-config
php artisan vendor:publish --tag=categories-factory