PHP code example of hosnyben / nova-nested-inputs

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

    

hosnyben / nova-nested-inputs example snippets


// in a Nova Resource

use HosnyBEN\NovaNestedInputs\NovaNestedInputs;

public function fields(Request $request)
{
    return [
            NovaNestedInputs::make('Category', 'category_id')
                ->options(function() {
                    return [
                        ['id' => 1, 'label' => 'Parent 1'],
                        ['id' => 2, 'label' => 'Parent 2'],
                        ['id' => 3, 'label' => 'Parent 3'],
                        [
                            'id' => 4,
                            'label' => 'Parent 4',
                            'children' => [
                                ['id' => 5, 'label' => 'Child 4.1'],
                                [
                                    'id' => 6, 
                                    'label' => 'Child 4.2',
                                    'children' => [
                                        ['id' => 8, 'label' => 'Child 4.2.1'],
                                        ['id' => 9, 'label' => 'Child 4.2.2'],
                                    ],
                                ],
                                ['id' => 7, 'label' => 'Child 4.3'],
                            ],
                        ],
                    ];
                })
                ->type('radio')
                ->color('#be860f')
                ->rules('

[
	[
		'id' => 1, // ID of the record
		'label' => 'My item', // String : Title of the item
		'disabled' => false, // Boolean
		'children' => [ // Array of nested item with the exact structure
			...
		]
    	],
    	...
]