Assume we have a setupupdateOperation() and setup() like this
public function setup()
{
$this->crud->setModel(MyEvent::class);
$this->crud->setEntityNameStrings(trans('backpack.application'), trans('backpack.applications'));
$this->crud->setRoute(backpack_url('application'));
}
protected function setupUpdateOperation(){
$this->crud->addFields([
[
'name' => 'my_evt_registration.application_status',
'label' => 'Application Status',
'type' => 'text',
],
]
}
As you can see, there is a model/table called MyEvent and it joins (1-to-1) to another table called my_evt_registration.
I expected that it will correctly identify the database table and column it has. In this case database table is my_evt_registration and column is application_status.
However, as it turns out, when I am using dd() to debug, here is what I found
// Expected Result
array:3 [â–¼
"name" => "application_status"
"type" => "text"
"label" => "Application Status"
]
// Incorrect Result
array:1 [â–¼
"application_status" => array:3 [â–¼
"name" => "vetting.application_status"
"label" => "Application Status"
"type" => "text"
]
]
Result in:
ErrorException
Undefined index: name
The file that is in question is this: \vendor\backpack\crud\src\app\Library\CrudPanel\Traits\Update.php.
When I run php artisan backpack:version the output is:
PHP 7.3.10 (cli) (built: Sep 24 2019 11:59:22) ( ZTS MSVC15 (Visual C++ 2017) x64 )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.3.10, Copyright (c) 1998-2018 Zend Technologies
v6.16.0@b47217e41868d3049ec545cbb713aa94c6f39e55
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 channels:
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
You can fix this temporarily by labeling the field yourself with the key:
$this->crud->addFields([
'my_evt_registration.application_status' => [
'name' => 'my_evt_registration.application_status',
'label' => 'Application Status',
'type' => 'text',
],
]);
By the way are you sure you are dumping a correct thing? I mean "name" => "vetting.application_status" is nowhere near 'name' => 'my_evt_registration.application_status',
You can fix this temporarily by labeling the field yourself with the key:
$this->crud->addFields([ 'my_evt_registration.application_status' => [ 'name' => 'my_evt_registration.application_status', 'label' => 'Application Status', 'type' => 'text', ], ]);By the way are you sure you are dumping a correct thing? I mean
"name" => "vetting.application_status"is nowhere near'name' => 'my_evt_registration.application_status',
My bad, I am trying to hide my custom field, but it seems I failed. :D
You can fix this temporarily by labeling the field yourself with the key:
$this->crud->addFields([ 'my_evt_registration.application_status' => [ 'name' => 'my_evt_registration.application_status', 'label' => 'Application Status', 'type' => 'text', ], ]);By the way are you sure you are dumping a correct thing? I mean
"name" => "vetting.application_status"is nowhere near'name' => 'my_evt_registration.application_status',
OK, after reading your code, I did not use your method. Instead I do this:
$this->crud->addFields([
[
'name' => 'application_status', // This is a real db column name
'label' => 'Application Status',
'entity' => 'my_evt_registration', // This is my 1-to-1 laravel model name, use the function name in Laravel, not table name.
// IN this case "Event" model has a 1-to-1 relationship to another model called "My_Event_Registration",
// the "Event" model has a function called "my_evt_registration" that
// contains the "hasOne()" function, so we put the key "entity" here.
// "entity" is backpack reserved keyword.
'type' => 'text',
],
]);
It works.
Most helpful comment
OK, after reading your code, I did not use your method. Instead I do this:
It works.