PHP code example of typicms / nestablecollection

1. Go to this page and download the library: Download typicms/nestablecollection 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/ */

    

typicms / nestablecollection example snippets


protected $fillable = [
    'parent_id',
    // …
];

use TypiCMS\NestableTrait;

Model::orderBy('parent_id')->get()->nest();

$collection->childrenName('children')->nest();

[
    '22' => 'Item 1 Title',
    '10' => '    Child 1 Title',
    '17' => '    Child 2 Title',
    '14' => 'Item 2 Title',
]

Model::orderBy('parent_id')->get()->nest()->listsFlattened();

Model::orderBy('parent_id')->get()->nest()->listsFlattened('name');

Model::orderBy('parent_id')->get()->nest()->setIndent('> ')->listsFlattened();

[
    '22' => 'Item 1 Title',
    '10' => '> Child 1 Title',
    '17' => '> Child 2 Title',
    '14' => 'Item 2 Title',
]

Model::orderBy('parent_id')->get()->noCleaning()->nest();