Crud: manual field definition not working with New, edit

Created on 19 Sep 2018  路  4Comments  路  Source: Laravel-Backpack/CRUD

Bug report

What I did:

commented out $this->crud->setFromDb();
added columns with addColumn

````
public function setup()
{
/*
|--------------------------------------------------------------------------
| CrudPanel Basic Information
|--------------------------------------------------------------------------
*/
$this->crud->setModel('App\Models\ResourceGroupRequest');
$this->crud->setRoute(config('backpack.base.route_prefix') . '/resourcegroup');
$this->crud->setEntityNameStrings('Resource Group Request', 'Resource Group Requests');

    /*
    |--------------------------------------------------------------------------
    | CrudPanel Configuration
    |--------------------------------------------------------------------------
    */

    // TODO: remove setFromDb() and manually define Fields and Columns
    // $this->crud->setFromDb();
    $this->crud->addColumn([
        'label' => 'Status',
        'type' => 'text',
        'name' => 'status',
        'priority' => 1,

    ]);
    $this->crud->addColumn('ResourceGroupName');
    $this->crud->addColumn('Subscription');
    $this->crud->addColumn('RequesterEmail');
    $this->crud->addColumn('created_at', 'Created');

    // add asterisk for fields that are required in ResourceGroupRequestRequest
    $this->crud->setRequiredFields(StoreRequest::class, 'create');
    $this->crud->setRequiredFields(UpdateRequest::class, 'edit');
    $this->crud->addFilter([
        'type' => 'simple',
        'name' => 'trashed',
        'label' => 'Show Deleted Records'
    ],
    false,
    function($values)
    { 
        // IF THE FILTER IS ACTIVE
        $this->crud->query->onlyTrashed();

    });
}

````

What I expected to happen:

Expect to see the 5 columns I specified on all Crud views (index, edit, create)

What happened:

Index looks great, the table displays just as expected.
'Edit' and 'Add new record' both display no fields, just the submit/cancel buttons.

What I've already tried to fix it:

Read documentation on $this->crud->addColumn

note this works fine if I leave $this->crud-setFromDB() in the code.

Backpack, Laravel, PHP, DB version:

latest

triage

Most helpful comment

For create and Update you have to define fields: https://backpackforlaravel.com/docs/3.4/crud-fields

Columns are only for index 馃槈

All 4 comments

Hello there! Thanks for opening your first issue on this repo!

Just a heads-up: Here at Backpack we use Github Issues only for tracking bugs. Talk about new features is also acceptable. This helps _a lot_ in keeping our focus on improving Backpack. If you issue is not a bug/feature, please help us out by closing the issue yourself and posting in the appropriate medium (see below). If you're not sure where it fits, it's ok, a community member will probably reply to help you with that.

Backpack communication mediums:

  • Bug Reports, Feature Requests - Github Issues (here);
  • Quick help (_How do I do X_) - Gitter Chatroom;
  • Long questions (_I have done X and Y and it won't do Z wtf_) - Stackoverflow, using the backpack-for-laravel tag;

Please keep in mind Backpack offers no official / paid support. Whatever help you receive here, on Gitter, Slack or Stackoverflow is thanks to our awesome _awesome_ community members, who give up some of their time to help their peers. If you want to join our community, just start pitching in. We take pride in being a welcoming bunch.

Thank you!

--
Justin Case
The Backpack Robot

For create and Update you have to define fields: https://backpackforlaravel.com/docs/3.4/crud-fields

Columns are only for index 馃槈

Closing this as I just noticed in the documentation that addColumn and addField are actually two distinct things, so it seems it's working as expected.

@tabacitu if you happen to see this, it would be neat if there was a way to set fields and columns from the db independently.

ie
````
//old:
$this->crud->setFromDb();

//new:
$this->crud->setIndexColumnsFromDb();
$this->crud->setFormFieldsFromDb();
````

This would accomplish the same thing, while making the scope of commenting these out clearer.
It also would have the added benefit of allowing a dev to easily create a custom index while relying on setFormFieldsFromDb() for the Create and Update screens.

Thanks!

@tswonke Thanks Thomas! I had _just_ noticed that and was typing a reply as yours came in.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

sseggio picture sseggio  路  3Comments

sonoftheweb picture sonoftheweb  路  3Comments

jorgepires picture jorgepires  路  3Comments

abewartech picture abewartech  路  3Comments

M0H3N picture M0H3N  路  3Comments