Adam Fiqrie Putra
Adam Fiqrie Putra

Reputation: 219

Passing my select id to route controller and show to another blade file

I'm trying to pass the selected id to controller using a route. But nothing happen shown at another blade file. Here, is my code

my blade contain that script

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

        });

state select

  <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>

cu select

<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>

open new window route via 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>

routes/web.php

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

Controller

public function branchCheckBoxList(Request $request) {

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

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


    }

Upvotes: 0

Views: 485

Answers (2)

Khusal Berva
Khusal Berva

Reputation: 134

$(document).on('change','#cu',function(){
{
    var state = $('#state option:selected').val();
    var cu = $('#cu option:selected').val();
    var viewurl = '{{ route("admin.booking.view", [":state",":cu"]) }}';
    viewurl = viewurl.replace(':state',state );
    var finalurl = viewurl.replace(':cu',cu );
    $('a.btn').attr('href',finalurl);
});

and in you route

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

and final in your controller

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

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

Upvotes: 0

Qonvex620
Qonvex620

Reputation: 3972

You cannot used request in your method arguments considering that you are using a get request in your route, to access those parameters change your controller to this.

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

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

Upvotes: 1

Related Questions