laravel 背包中的 InlineCreate 操作无法从父表单检索数据
Unable to retrieve data from parent form in InlineCreate operation in backpack for laravel
我在 Backpack 中为 Laravel 实现了 InlineCreate 操作并且工作正常,但我的字段依赖于其他字段,我无法在模式或设置操作中获取父字段信息。
字段定义
$this->crud->addField([
'name' => 'cliente_contacto',
'type' => "relationship",
'ajax' => true,
//'inline_create' => true,
'inline_create' => [ // specify the entity in singular
'entity' => 'cliente_contacto', // the entity in singular
// OPTIONALS
'force_select' => true, // should the inline-created entry be immediately selected?
'modal_class' => 'modal-dialog modal-lg', // use modal-sm, modal-lg to change width
'modal_route' => route('cliente-contacto-inline-create'), // InlineCreate::getInlineCreateModal()
'create_route' => route('cliente-contacto-inline-create-save'), // InlineCreate::storeInlineCreate()
'include_main_form_fields' => ['proyecto'] // pass certain fields from the main form to the modal
],
// 'data_source' => backpack_url('presupuesto/fetch/cliente-contacto'),
// 'placeholder' => 'Seleccione un elemento',
'minimum_input_length' => 0,
'dependencies' => ['cliente'], // when a dependency changes, this select2 is reset to null
//'method' => 'POST', // optional - HTTP method to use for the AJAX call (GET, POST)
//'include_all_form_fields' => true, //sends the other form fields along with the request so it can be filtered.
'tab' => 'Datos Principales',
'wrapper' => [
'class' => 'col-md-3'
]
]);
ClienteContactoCrudController
protected function setupInlineCreateOperation()
{
$parent_loaded_fields = request()->get('parent_loaded_fields');
}
但我无法获取该字段。
文档:
https://backpackforlaravel.com/docs/5.x/crud-operation-inline-create#how-to-use-1
'include_main_form_fields' => ['field1', 'field2'], // pass certain fields from the main form to the modal
不要说怎么得到那个值。
我找到了这个:https://github.com/Laravel-Backpack/CRUD/issues/2925#issuecomment-644060749
我可以得到:
'entity' => request()->get('entity'),
'modalClass' => request()->get('modal_class'),
但是
'parentLoadedFields' => request()->get('parent_loaded_fields')
不工作
如何获取父字段值?
你应该用 request('main_form_fields')
得到它们。
我刚刚向文档提交了一个 PR 以参考:https://github.com/Laravel-Backpack/docs/pull/341
干杯
我在 Backpack 中为 Laravel 实现了 InlineCreate 操作并且工作正常,但我的字段依赖于其他字段,我无法在模式或设置操作中获取父字段信息。
字段定义
$this->crud->addField([
'name' => 'cliente_contacto',
'type' => "relationship",
'ajax' => true,
//'inline_create' => true,
'inline_create' => [ // specify the entity in singular
'entity' => 'cliente_contacto', // the entity in singular
// OPTIONALS
'force_select' => true, // should the inline-created entry be immediately selected?
'modal_class' => 'modal-dialog modal-lg', // use modal-sm, modal-lg to change width
'modal_route' => route('cliente-contacto-inline-create'), // InlineCreate::getInlineCreateModal()
'create_route' => route('cliente-contacto-inline-create-save'), // InlineCreate::storeInlineCreate()
'include_main_form_fields' => ['proyecto'] // pass certain fields from the main form to the modal
],
// 'data_source' => backpack_url('presupuesto/fetch/cliente-contacto'),
// 'placeholder' => 'Seleccione un elemento',
'minimum_input_length' => 0,
'dependencies' => ['cliente'], // when a dependency changes, this select2 is reset to null
//'method' => 'POST', // optional - HTTP method to use for the AJAX call (GET, POST)
//'include_all_form_fields' => true, //sends the other form fields along with the request so it can be filtered.
'tab' => 'Datos Principales',
'wrapper' => [
'class' => 'col-md-3'
]
]);
ClienteContactoCrudController
protected function setupInlineCreateOperation()
{
$parent_loaded_fields = request()->get('parent_loaded_fields');
}
但我无法获取该字段。 文档: https://backpackforlaravel.com/docs/5.x/crud-operation-inline-create#how-to-use-1
'include_main_form_fields' => ['field1', 'field2'], // pass certain fields from the main form to the modal
不要说怎么得到那个值。
我找到了这个:https://github.com/Laravel-Backpack/CRUD/issues/2925#issuecomment-644060749
我可以得到:
'entity' => request()->get('entity'),
'modalClass' => request()->get('modal_class'),
但是
'parentLoadedFields' => request()->get('parent_loaded_fields')
不工作
如何获取父字段值?
你应该用 request('main_form_fields')
得到它们。
我刚刚向文档提交了一个 PR 以参考:https://github.com/Laravel-Backpack/docs/pull/341
干杯