为了账号安全,请及时绑定邮箱和手机立即绑定

select2 依赖于另一个字段的字段

select2 依赖于另一个字段的字段

PHP
摇曳的蔷薇 2023-04-02 10:51:04
我想实现本教程中的代码展示:https://backpackforlaravel.com/docs/4.1/crud-how-to#add-a-select2-field-that-depends-on-another-field但是,此行返回null值:$form = collect($request->input('form'))->pluck('value', 'name');我不知道我是否应该input('form')在这里使用它,因为它取自版本 3.4 的文档有人知道它是否适用于版本 4.克鲁德控制器:// CRUD::field('sub_district_id')//     ->type('select2')//     ->label('Kecamatan')//     ->entity('sub_district')//     ->attribute('sub_district_name')//     ->model('App\Models\SubDistrict')//     ->wrapper(['class' => 'form-group col-md-6']);CRUD::field('sub_district_id')    ->type('relationship')    ->label('Kecamatan')    ->attribute('sub_district_name')    ->include_all_form_fields(true)    ->wrapper(['class' => 'form-group col-md-6']);CRUD::field('village_id')    ->type('select2_from_ajax')    ->label('Desa/Kelurahan')    ->entity('village')    ->attribute('village_name')    ->model("App\Models\Village")    ->wrapper(['class' => 'form-group col-md-6'])    ->data_source(url('api/village'))    ->placeholder('Pilih Desa/Kelurahan')    ->minimum_input_length(0)    ->dependencies(['sub_district_id'])    ->method('GET'); // optional - HTTP method to use for the AJAX call (GET, POST)接口控制器:$search_term = $request->input('q');$form = collect($request->input('form'))->pluck('value', 'name');// dump($form);$options = Village::query();if (!$form['sub_district_id']) {    return [];}// if a category has been selected, only show articles in that categoryif ($form['sub_district_id']) {    $options = $options->where('sub_district_id', $form['sub_district_id']);}if ($search_term) {    $results = $options->where('village_name', 'LIKE', '%' . $search_term . '%')->paginate(10);} else {    $results = $options->paginate(10);}return $options->paginate(10);
查看完整描述

1 回答

  • 1 回答
  • 0 关注
  • 73 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信