-
Notifications
You must be signed in to change notification settings - Fork 919
Description
Bug report
What I did
I called modifyField method to change the field into a select2 field.
What I expected to happen
It should just convert the field from textfield to select2 and not shows that error.
What happened
When I create a new entry, I got Undefined index: pivot error
Here's the code
$this->crud->modifyField('client_category_id', [ // Select2
'label' => "Kategori Klien",
'type' => 'select2',
'name' => 'client_category_id', // the db column for the foreign key
'entity' => 'category', // the method that defines the relationship in your Model
'attribute' => 'category_name', // foreign key attribute that is shown to user
// optional
'model' => "App\Models\Client_category", // foreign key model
// 'default' => 2, // set the default value of the select2
'options' => (function ($query) {
return $query->orderBy('lft', 'ASC')->where('depth', 1)->get();
}), // force the related options to be a custom query, instead of all(); you can use this to filter the results show in the select
]);
What I've already tried to fix it
When I first remove the field, then call addField method right below the removeField method, the error was gone.
Here's the code
$this->crud->removeField('client_category_id');
$this->crud->addField([
'label' => "Kategori Klien",
'type' => 'select2',
'name' => 'client_category_id',
'entity' => 'category',
'attribute' => 'category_name',
'model' => "App\Models\Client_category",
'options' => (function ($query) {
return $query->orderBy('lft', 'ASC')->where('depth', 1)->get();
}),
]);
I've also tried to remove the model parameter when calling modifyField, but it still shows the error
Backpack, Laravel, PHP, DB version
When I run php artisan backpack:version the output is:
PHP VERSION:
PHP 7.4.5 (cli) (built: Apr 14 2020 16:17:34) ( ZTS Visual C++ 2017 x64 )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
LARAVEL VERSION:
v7.16.1@dc9cd8338d222dec2d9962553639e08c4585fa5b
BACKPACK VERSION:
4.1.11@acc4df836505a612d1dd15a39ce02be87e36577d
