Crud: [Feature Request][4.0] Make all CrudPanel methods chainable

Created on 22 Aug 2018  路  2Comments  路  Source: Laravel-Backpack/CRUD

When we define our CrudPanel in setup(), there's really no reason we can't make the API fluent (just return the CrudPanel object on the calls).

// this

$this->crud->setModel('App\Models\Monster')
    ->setRoute(config('backpack.base.route_prefix').'/monster')
    ->setEntityNameStrings('monster', 'monsters');

// should be easier to read than this

$this->crud->setModel('App\Models\Monster')
$this->crud->setRoute(config('backpack.base.route_prefix').'/monster');
$this->crud->setEntityNameStrings('monster', 'monsters');

Just like

// this
$this->crud->addField([
    'name'  => 'text',
    'label' => 'Text',
    'type'  => 'text',
    'tab'   => 'Simple',
])->addField([
    'name'  => 'email',
    'label' => 'Email',
    'type'  => 'email',
    'tab'   => 'Simple',
])->addField([   // Textarea
    'name'  => 'textarea',
    'label' => 'Textarea',
    'type'  => 'textarea',
    'tab'   => 'Simple',
]);

// is slightly easier on the eye than this
$this->crud->addField([
    'name'  => 'text',
    'label' => 'Text',
    'type'  => 'text',
    'tab'   => 'Simple',
]);

$this->crud->addField([
    'name'  => 'email',
    'label' => 'Email',
    'type'  => 'email',
    'tab'   => 'Simple',
]);

$this->crud->addField([   // Textarea
    'name'  => 'textarea',
    'label' => 'Textarea',
    'type'  => 'textarea',
    'tab'   => 'Simple',
]);

Note: we already have this, with addField(). We should just make sure all our relevant methods are chainable.

triage

Most helpful comment

My personal favorite is

$this->crud->addFields([
    [
        'name'  => 'text',
        'label' => 'Text',
        'type'  => 'text',
        'tab'   => 'Simple',
    ],
    [
        'name'  => 'email',
        'label' => 'Text',
        'type'  => 'text',
        'tab'   => 'Simple',
    ],
    [
        'name'  => 'something',
        'label' => 'Text',
        'type'  => 'text',
        'tab'   => 'Simple',
    ],
]);

;-)

All 2 comments

My personal favorite is

$this->crud->addFields([
    [
        'name'  => 'text',
        'label' => 'Text',
        'type'  => 'text',
        'tab'   => 'Simple',
    ],
    [
        'name'  => 'email',
        'label' => 'Text',
        'type'  => 'text',
        'tab'   => 'Simple',
    ],
    [
        'name'  => 'something',
        'label' => 'Text',
        'type'  => 'text',
        'tab'   => 'Simple',
    ],
]);

;-)

Yeah... does not sound like this is worth it. addFields() already does a good job.
Thanks for putting me in my place @tswonke :-)

Was this page helpful?
0 / 5 - 0 ratings