2014-10-14 8 views
0

У меня возникают проблемы с этой переменной. После заполнения деталей формы и нажатия кнопки «резерв» появится эта ошибка. 'Неопределенная переменная: gcount'. Я включил необходимое «-> с» на части контроллера, но все же он показывает ошибку. В чем проблема?Неопределенная переменная: gcount Laravel 4

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 protected]'))}}</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

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]); 
}} 

Я просто включить свои маршруты, ошибка может прийти оттуда.

routes.php

Route::post('flight/onewayflightterms','[email protected]'); 
Route::post('flight/onewayflightfillup','[email protected]') 

ответ

1

Проблема заключается в том, что линия:

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

Вы не проходят здесь gcount. Вы должны изменить его на:

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

и, очевидно, вам нужно добавить $guestcount= $children+$adult+$infant; до того, что так же, как вы это делали в первой функции

Смежные вопросы