[英]Unable to retrieve data from parent form in InlineCreate operation in backpack for laravel
我在背包中為 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
干杯
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.