PHP code example of gregoryduckworth / nestablecollection

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

    

gregoryduckworth / nestablecollection example snippets


protected $fillable = array(
    'parent_id',
    // …
}

use TypiCMS\NestableTrait;

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

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

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

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

Model::orderBy('parent_id')->get()->nest('parent_id')->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('parent_id');