2016-12-06 52 views
0

您好我有以下形式:Laravel 5.3,在驗證失敗會話不閃任何

 <form action="{{ route('postCustomerInfo') }}" method="post" class="shipping-form"> 
      {{ csrf_field() }} 
      <input type="hidden" name="note" value="hidden_note_field"> 
      <input type="hidden" name="country_id" value="1"> 
       <div class="form-checkout"> 
       <div class="form-fields"> 
        @if($errors->has('name'))<div class="input-box error" data-error="{{ $errors->first('name') }}"> 
         @else<div class="input-box"> 
        @endif 
         <input type="text" name="name" value={{ old('name') }}> 
         <label for="">name</label> 
        </div> 
        @if($errors->has('phone'))<div class="input-box error" data-error="{{ $errors->first('phone') }}"> 
         @else <div class="input-box"> 
        @endif 
         <input type="text" name="phone" value={{ old('phone') }} onkeypress='return event.charCode >= 48 && event.charCode <= 57'> 
         <label for="">phone</label> 
        </div> 
        @if($errors->has('email'))<div class="input-box error" data-error="{{ $errors->first('email') }}"> 
         @else <div class="input-box"> 
        @endif 
         <input type="text" name="email" value="{{ old('email') }}"> 
         <label for="">email</label> 
        </div> 
        <div class="row"> 
         <div class="col-xs-5 col-sm-5 col-md-6"> 
          @if($errors->has('city'))<div class="input-box error" data-error="{{ $errors->first('city') }}"> 
           @else<div class="input-box"> 
          @endif 
           <input type="text" name="city" value="{{ old('city') }}"> 
           <label for="">city</label> 
          </div> 
         </div> 
         <div class="col-xs-7 col-sm-7 col-md-6"> 
          @if($errors->has('postal_code'))<div class="input-box error" data-error="{{ $errors->first('postal_code') }}"> 
           @else<div class="input-box error" data-error="{{ $errors->first('postal_code') }}"> 
          @endif 
           <input type="text" name="postal_code" value="{{ old('postal_code') }}"> 
           <label for="">postal code</label> 
          </div> 
         </div> 
        </div> 
        @if($errors->has('address_line'))<div class="input-box error" data-error="{{ $errors->first('address_line') }}"> 
         @else<div class="input-box error" data-error="{{ $errors->first('address_line') }}"> 
        @endif 
         <input type="text" name="address_line" value={{ old('address_line') }}> 
         <label for="">address</label> 
        </div> 
       </div> 
      </div> 
     </form> 
     <a href="" class="btn action">Go to <span>shipping</span></a> 

我通過jQuery

$(document).ready(function() { 
     $('.btn.action').on('click','',function (e) { 
      e.preventDefault(); 
      var $form = $('form.shipping-form'); 
      $form.submit(); 
     }); 
    }); 

提交表單和我FormRequest類:

class CustomerInformationRequest extends FormRequest { 
/** 
* Determine if the user is authorized to make this request. 
* 
* @return bool 
*/ 
public function authorize() { 
    return true; 
} 

/** 
* Get the validation rules that apply to the request. 
* 
* @return array 
*/ 
public function rules() { 
    return [ 
     'name'   => 'required|min:5|max:50', 
     'email'   => 'required|email|min:5|max:50', 
     'phone'   => 'required|min:3|max:20', 
     'country_id' => 'required', 
     'city'   => 'required|min:3', 
     'postal_code' => 'required|digits:4', 
     'address_line' => 'required|min:5|max:50', 
     'note'   => '' 
    ]; 
} 

}

我在StackOverflow中讀到這個線程:Laravel 5 input old is empty但我不認爲這實際上是我的問題。而且我的{{old('values')}}是空的,我不知道爲什麼?

+0

你有沒有使用CustomerInformationRequest $ request在你的控制器方法中注入請求? –

+0

是啊!公共職能customerInformation(CustomerInformationRequest $請求){ Session :: put('checkout.customer_information',$ request-> input()); } – deshi

+0

也在我的會話中,我不能看到_old_input鍵,當我在葉片dd後提交表格 – deshi

回答

0
/** 
* The application's global HTTP middleware stack. 
* 
* These middleware are run during every request to your application. 
* 
* @var array 
*/ 
protected $middleware = [ 
    \Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode::class, 
]; 

/** 
* The application's route middleware groups. 
* 
* @var array 
*/ 
protected $middlewareGroups = [ 
    'web' => [ 
     \App\Http\Middleware\EncryptCookies::class, 
     \Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class, 
     \Illuminate\Session\Middleware\StartSession::class, 
     \Illuminate\View\Middleware\ShareErrorsFromSession::class, 
     \App\Http\Middleware\VerifyCsrfToken::class, 
     \Illuminate\Routing\Middleware\SubstituteBindings::class, 
     \App\Http\Middleware\BeforeAutoTrimmer::class 
    ], 

    'api' => [ 
     'throttle:60,1', 
     'bindings', 
    ], 
]; 

/** 
* The application's route middleware. 
* 
* These middleware may be assigned to groups or used individually. 
* 
* @var array 
*/ 
protected $routeMiddleware = [ 
    'auth' => \Illuminate\Auth\Middleware\Authenticate::class, 
    'auth.basic' => \Illuminate\Auth\Middleware\AuthenticateWithBasicAuth::class, 
    'bindings' => \Illuminate\Routing\Middleware\SubstituteBindings::class, 
    'can' => \Illuminate\Auth\Middleware\Authorize::class, 
    'guest' => \App\Http\Middleware\RedirectIfAuthenticated::class, 
    'throttle' => \Illuminate\Routing\Middleware\ThrottleRequests::class, 
    'setCurrency'=>\App\Http\Middleware\SetCurrency::class, 
    'checkout'=>\App\Http\Middleware\Checkout::class, 
];}`. 

我加 \App\Http\Middleware\BeforeAutoTrimmer::class誰在乎修剪我的所有形式: public function handle($request, Closure $next) { $request->merge(array_map('trim', $request->all())); return $next($request); } ,這 'setCurrency'=>\App\Http\Middleware\SetCurrency::class誰在乎貨幣設置從數據庫會話:

'公共功能手柄($請求,關閉$如果(!Session :: has('currency')){0} {0} ; $ currencyData = Currency :: where('code',$ currency-> code) - > select('symbol_position','symbol','code') - > first();

 Session::put('currency', $currencyData); 
     Session::save(); 
     return $next($request); 
    } 
    return $next($request);}` 

'checkout'=>\App\Http\Middleware\Checkout::class,誰在乎重定向我,如果車在會議上是空的:

'公共功能手柄($請求,一次閉合$) {

if(!Session::has('cart')){ 
     return redirect()->route('home'); 
    } 
    return $next($request); 
}` 

但其餘的我認爲他們是默認的laravel,我沒有碰他們