首页 > 解决方案 > 如何从背包 laravel 中的 select2_from_ajax_multiple 中保存多个值

问题描述

每个人

我正在尝试从选择选项中保存多个值,但我不知道如何在 laravel Backpack中保存。我一直在尝试解决 2 天以来的错误,但它仍然无法从我这边工作。

请看一下,我们将不胜感激。
这是多选选项的屏幕截图---在此处输入图像描述

但它不会保存在数据库中,但如果我要编辑记录,它会给出这个错误---在此处输入图像描述

这是我的控制器代码

CRUD::addField([ // select2_from_ajax: 1-n relationship
      'label'                => "City Name", // Table column heading
      'type'                 => 'select2_from_ajax_multiple',
      'name'                 => 'location_id', // the column that contains the ID of that connected entity;
      'entity'               => 'location', // the method that defines the relationship in your Model
      'attribute'            => 'name', // foreign key attribute that is shown to user
      'tab'                  => 'Texts',
      'data_source'          => url('api/location'), // url to controller search function (with /{id} should return model)
      'placeholder'          => 'Select location', // placeholder for the select
      'include_all_form_fields' => true, //sends the other form fields along with the request so it can be filtered.
         'minimum_input_length' => 0, // minimum characters to type before querying results
      'dependencies'         => ['state'], // when a dependency changes, this select2 is reset to null
      // 'method'                    => 'GET', // optional - HTTP method to use for the AJAX call (GET, POST)
      "allows_multiple" => true,
      'pivot' => true,
]);

标签: phplaravellaravel-backpack

解决方案


推荐阅读