首页 > 解决方案 > 将我的选择 ID 传递给路由控制器并显示到另一个刀片文件

问题描述

我正在尝试将所选内容传递idcontroller使用route. 但是在另一个刀片文件中没有显示任何内容。这是我的代码

我的刀片包含那个脚本

 $("#state").on("change", function() {
            var id = $(this).val();
            console.log(id)
            var cuid = document.getElementById("cu").value;  
            console.log(cuid)

        });

状态选择

  <div class="col-md-12 form-group" id="stateBranch">
                    <label for="sm" class="control-label">{{ __('messages.state') }}</label>
                    <select name="state" id="state" class="input-sm form-control">
            <option value="">{{ __('messages.select') }}</option>

                      @if(!empty(request()->session()->get('stateList')))
                                    @foreach(request()->session()->get('stateList') as $state)
                                        <option value="{{ $state->st_state_code }}">{{ $state->st_state_desc }}</option>
                                    @endforeach
                                @endif
                    </select>

        </div>

选择

<div class="col-md-12 form-group" id="custbranchreport">
                    <label for="sm" class="control-label">{{ __('messages.module.customer') }}<span class="compulsory"> * </span></label>
                    <select name="cu" id="cu" class="input-sm form-control" onchange="">
            <option value="">{{ __('messages.select') }}</option>

             @if(!empty($custList))
                                    @foreach($custList as $cu)
                                        <option value="{{ $cu->cu_customer_ID }}">{{ $cu->cu_customer_Shortname }}-{{ $cu->cu_customer_Name }}</option>
                                    @endforeach
                                @endif

                    </select>
                    <input id="hid" type="hidden" name="hid" value=""/>
        </div>

通过 onclick 打开新窗口路由

 <a class="btn btn-sm btn-default pull-right" type="button" title="Search Branch" onclick="openNewWindow('{{ route('reporting.branchCheckBoxList', ['cu' ,'state']) }}')" ><i class="fa fa-hand-o-up"></i>&nbsp;&nbsp;Choose Branch</a>

路线/web.php

 Route::get('reporting/branchCheckBoxList/{cuid}/{stid?}','GenReportController@branchCheckBoxList')->name('reporting.branchCheckBoxList');

控制器

public function branchCheckBoxList(Request $request) {

         $cuid = $request->get('cuid');
         $stid = $request->get('stid');

    return view('report.BranchCheckBoxList',  compact('cuid','stid'));


    }

标签: javascriptphplaravel

解决方案


考虑到您在路由中使用 get 请求,您不能在方法参数中使用请求,以访问这些参数将您的控制器更改为此。

public function branchCheckBoxList($cuid, $stid = '') {
    $cuid = $cuid;
    $stid = $stid;

    return view('report.BranchCheckBoxList',  compact('cuid','stid'));
}

推荐阅读