简体   繁体   English

未定义的变量:gcount Laravel 4

[英]Undefined variable: gcount Laravel 4

I'm having trouble with this variable. 我在使用此变量时遇到麻烦。 After filling up the details on the form and by clicking the reserve button, this error would come up. 在填写表格的详细信息并单击保留按钮后,将出现此错误。 'Unidentified variable: gcount'. “不确定的变量:gcount”。 I have included the necessary '->with' on the controller part but still, it shows the error. 我已经在控制器部分添加了必要的“-> with”,但是仍然显示错误。 What seems to be the problem here? 这里似乎是什么问题?

onewayflightfillup.blade.php onewayflightfillup.blade.php

    @extends('layouts.master')
@section('content')
     {{ Form::open(['url'=>'flight/onewayflightfillup']) }}

             <!--~~~~~~~~~~~~~~~~~~~~~~~~~Date Picker HTML~~~~~~~~~~~~~~~~~~~~~~~~~-->
          {{ HTML::style('//code.jquery.com/ui/1.11.1/themes/smoothness/jquery-ui.css') }}
          {{ HTML::script('//code.jquery.com/jquery-1.10.2.js') }}
          {{ HTML::script('//code.jquery.com/ui/1.11.1/jquery-ui.js') }}

<div class="row">

  <div class="col-md-8">
    <div class="page-header"><h2>Guest Details</h2><small>Fill up the necessary items.<br/><span class="label label-danger">* Required</span></small></div><br/>
    <div class="input-group input-group-sm">
    @for ($z = 0; $z < $gcount; $z++)
              <table>
                <tr>
                  <td>{{ Form::label('title','*Title ',array('class'=>'class="control-label"')) }}</td>
                  <td>{{ Form::select('title[]', ['Mr'=>'Mr', 'Ms'=>'Ms'],'Mr',array('class'=>'form-control')) }} </td>
                </tr>
                <tr>
                  <td>{{ Form::label('birthday','*Birthday', array('class'=>'"input-group-addon btn"'))}}</td>
                  <td>{{ Form::text('birthday[]', '', array('id' => 'calum','data-date-format'=>'yyyy-mm-dd','class' => 'form-control')) }}</td>
                </tr>
                <tr>
                  <td>{{ Form::label('name','*Name ',array('class'=>'class="control-label"')) }} </td>
                  <td>{{ Form::text('lastname[]', '',array('class' => 'form-control','placeholder'=>'lastname'))}}</td>
                  <td>{{ Form::text('firstname[]', '',array('class' => 'form-control','placeholder'=>'firstname'))}}</td>
                  <td>{{ Form::text('middlename[]', '',array('class' => 'form-control','placeholder'=>'middlename'))}}</td>
                  <td></td>
                </tr>
                <tr>
                  <td>{{ Form::label('streetadd','*Street Address ',array('class'=>'class="control-label"')) }} </td>
                  <td>{{ Form::text('streetadd[]', '',array('class' => 'form-control','placeholder'=>'street address'))}}</td>
                </tr>
                <tr>
                  <td>{{ Form::label('city','*City ',array('class'=>'class="control-label"')) }} </td>
                  <td>{{ Form::text('city[]', '',array('class' => 'form-control','placeholder'=>'city'))}}</td>
                </tr>
                <tr>
                  <td>{{ Form::label('zipcode','*Zip code ',array('class'=>'class="control-label"')) }} </td>
                  <td>{{ Form::text('zipcode[]', '',array('class' => 'form-control','placeholder'=>'zipcode'))}}</td>
                </tr>
                <tr>
                  <td>{{ Form::label('country','*Country ',array('class'=>'class="control-label"')) }} </td>
                  <td>{{ Form::text('country[]', '',array('class' => 'form-control','placeholder'=>'country'))}}</td>
                </tr>
                <tr>
                  <td>{{ Form::label('home','*Home phone ',array('class'=>'class="control-label"')) }} </td>
                  <td>{{ Form::text('home[]', '',array('class' => 'form-control','placeholder'=>'home phone no.'))}}</td>
                </tr>
                <tr>
                  <td>{{ Form::label('work','Work phone ',array('class'=>'class="control-label"')) }} </td>
                  <td>{{ Form::text('work[]', '',array('class' => 'form-control','placeholder'=>'work phone no.'))}}</td>
                </tr>
                <tr>
                  <td>{{ Form::label('fax','Fax ',array('class'=>'class="control-label"')) }}</td>
                  <td>{{ Form::text('fax[]', '',array('class' => 'form-control','placeholder'=>'fax'))}}</td>
                </tr>
                <tr>
                  <td>{{ Form::label('mobile','*Mobile phone ',array('class'=>'class="control-label"')) }}</td>
                  <td>{{ Form::text('mobile[]', '',array('class' => 'form-control','placeholder'=>'mobile phone no.'))}}</td>
                </tr>
                <tr>
                  <td>{{ Form::label('email','*Email Add ',array('class'=>'class="control-label"')) }}</td>
                  <td>{{Form::text('email[]', '',array('class' => 'form-control','placeholder'=>'email@website.com'))}}</td>
                </tr>
                <tr>
                  <td>{{ Form::label('cemail','*Confirm Email Add &nbsp;',array('class'=>'class="control-label"')) }} </td>
                  <td>{{Form::text('cemail[]', '',array('class' => 'form-control','placeholder'=>'confirm email add'))}}</td>
                    </tr>
                  <hr>
              @endfor
                    <tr>
                      <td></td>
                      <td></td>
                      <td></td>
                      <td><p class="text-right">{{ Form::submit('Reserve',array('class'=>'btn btn-info btn-lg btn-block')) }}</td>
                    </tr>
                  </table>
          </div>
      </div>

      <div class="col-md-4">
        @if ($errors->has())
              <div class="page-header">
                <h4>Opps!</h4><small>You've place an invalid entry</small>
              </div>
                  @foreach ($errors->all() as $error)
                  <div class="alert alert-danger" role="alert">
                     {{$error}}</br> 
                  </div> 
                  @endforeach
            @endif
      </div>
    </div>

{{ Form::close() }}

      <script>
       $(function() {
         $( "#calum" ).datepicker();
       });
      </script>
@endsection  

OnewayflightController.php OnewayflightController.php

  public function onewayflightfillup(){
  $children=Session::get('children');
  $adult=Session::get('adult');
  $infant=Session::get('infant');

  $guestcount= $children+$adult+$infant;
  return View::make('content.onewayflightfillup')->with(['gcount'=>$guestcount]);
   }



     public function onewayflightshow()
       {  $children=Session::get('children');
          $adult=Session::get('adult');
          $infant=Session::get('infant');
          $to=Session::get('destinationto');
          $from=Session::get('destinationfrom');
          $dept=Session::get('departure');

          $show = DB::table('oneways')->get();


foreach ($show as $user)
        {  
                $adultFee = ($user->fare)*$adult;
                /*------------------------Child Fee------------------------*/
                $partialFee1 = ($user->fare)*.05;
                $partialFee2 = ($user->fare)-$partialFee1;
                $childFee = $partialFee2*$children;
            /*------------------------Infant Fee------------------------*/
            $partialFee3 = ($user->fare)*.10;
            $partialFee4 = ($user->fare)-$partialFee3;
            $infantFee = $partialFee2*$infant;
        }  
            $payment = ($adultFee+$childFee+$infantFee);

           $rules = array(
          'title'         => 'required',             
          'lastname'      => 'required',  
          'email'         => 'required|email',
          'cemail'        => 'required|same:email',    
          'firstname'     => 'required',
          'middlename'    => 'required',
          'birthday'      => 'required',
          'city'          => 'required',
          'streetadd'     => 'required',
          'zipcode'       => 'required|max:4',
          'country'       => 'required',
          'home'          => 'required|max:7',
          'mobile'        => 'required|max:12'
        );

      $validator = Validator::make(Input::all(), $rules);
      if ($validator->fails()) {

        $messages = $validator->messages();
        return View::make('content.onewayflightfillup')->withErrors($validator);

      $c = count(Input::get('title'));

      $titles = Input::get('title');
      $lastnames = Input::get('lastname');
      $firstnames = Input::get('firstname');
      $middlenames = Input::get('middlename');
      $birthdays = Input::get('birthday');
      $citys = Input::get('city');
      $streetadds = Input::get('streetadd');
      $zipcodes = Input::get('zipcode');
      $countrys = Input::get('country');
      $homes = Input::get('home');
      $works = Input::get('work');
      $faxs = Input::get('fax');
      $mobiles = Input::get('mobile');
      $emails = Input::get('email');

      for( $i=0; $i < $c; ++$i ) {
        $reserve = new Reserves;
        $reserve->title = $titles[$i];
        $reserve->lastname = $lastnames[$i];
        $reserve->firstname= $firstnames[$i];
        $reserve->middlename = $middlenames[$i];
        $reserve->birthday = $birthdays[$i];
        $reserve->city = $citys[$i];
        $reserve->streetadd = $streetadds[$i];
        $reserve->zipcode = $zipcodes[$i];
        $reserve->country = $countrys[$i]; 
        $reserve->home = $homes[$i];
        $reserve->work = $works[$i];
        $reserve->fax = $faxs[$i];
        $reserve->mobile = $mobiles[$i];
        $reserve->email = $emails[$i];
        $reserve->children = $children;
        $reserve->adult = $adult;
        $reserve->infant = $infant;
        $reserve->destinationfrom = $from;
        $reserve->destinationto = $to;
        $reserve->departure = $dept;
        $reserve->payment = $payment;

        $reserve->save();      
}
        $reserves = $reserve->id;
        $res = DB::table('reserves')->where('id', '=' ,$reserves)->get();
       return View::make('content.onewayflightshow2')->with(['showing'=>$res]);
}}

I'll just include my routes, the error might come from there. 我只包括我的路线,错误可能来自那里。

routes.php routes.php文件

Route::post('flight/onewayflightterms','OnewayflightController@onewayflightfillup');
Route::post('flight/onewayflightfillup','OnewayflightController@onewayflightshow')

The problem is that line: 问题是那条线:

return View::make('content.onewayflightfillup')->withErrors($validator);

You don't pass here gcount . 你不经过此地gcount You should change it into: 您应该将其更改为:

return View::make('content.onewayflightfillup')->withErrors($validator)->with(['gcount'=>$guestcount]);

and obviously you need to add $guestcount= $children+$adult+$infant; 很明显,您需要添加$guestcount= $children+$adult+$infant; before that the same as you did in the first function 在此之前,您与第一个功能相同

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM