PHP code example of onkbear / backpack-nested-crud

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

    

onkbear / backpack-nested-crud example snippets


class UserCrudController extends CrudController
{
    use \Backpack\CRUD\app\Http\Controllers\Operations\ListOperation;
    use \Backpack\CRUD\app\Http\Controllers\Operations\CreateOperation;
    use \Backpack\CRUD\app\Http\Controllers\Operations\UpdateOperation;

    public function setup()
    {
        CRUD::setModel('App\Models\User');
        CRUD::setRoute(config('backpack.base.route_prefix').'/user');
        CRUD::setEntityNameStrings('user', 'users');
    }

    protected function setupListOperation()
    {
        CRUD::addColumns(['name']);
    }

    protected function setupCreateOperation()
    {
        CRUD::addField([
            'name'  => 'name',
            'label' => 'Name',
            'type'  => 'text',
            'tab'   => 'Texts',
        ]);
    }

    protected function setupUpdateOperation()
    {
        $this->setupCreateOperation();

        CRUD::addField([
            'name'      => 'comments',
            'label'     => 'Comment',
            'type'      => 'nested_crud',
            'target'    => 'comment',
            'model'     => 'App\Models\Comment',
            'tab'       => 'Comments',  // optional
        ]);
    }
}

 php
    Route::crud('user/', 'UserCrudController');
    Route::group(['prefix' => 'user/{user_id}'], function() {
        Route::crud('comment', 'UserCommentCrudController');
    });
 php
// UserCommentCrudController.php

    protected function setupNestedListOperation()
    {
        $this->crud->setListView('nested_crud::nested_grid_list');
    }