0
我在laravel有問題。這個問題只在生產服務器上,在我的本地服務器上是工作屬性。所以也許這是我不知道的配置。Laravel 5.2 Flash舊的和重定向後空錯誤
所以當我發送一個表單,錯誤的值時,laravel驗證器系統應該將用戶重定向到表單並顯示錯誤。
這是代碼我的控制器:
$rules = array(
'nombre' => 'required|min:3|max:80',
'email' => 'required|email',
'asunto'=>'required|min:3|max:200',
'mensaje'=>'required|min:5|max:1000',
//'g-recaptcha-response' => 'required|recaptcha',
);
$validation = Validator::make($request->all(), $rules);
//si la validación falla redirigimos al formulario de registro con los errores
//y con los campos que nos habia llenado el usuario
if ($validation->fails())
{
return Redirect::to('/#contacto')->withErrors($validation->messages())->withInput();
}
/#CONTACTO與錨CONTACTO主航線所以這應該重定向到家裏。還行吧。
這是我route.php
Route::get('/', function() {
return view('web.index');
});
Route::post('/contacto/enviar', '[email protected]');
這是我的內核
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,
],
'api' => [
'throttle:60,1',
],
];
這是我的觀點,即應顯示錯誤結果。
<form name="contacto" method="post" action="/contacto/enviar"><input type="hidden" name="_token" value="<?php echo csrf_token(); ?>">
<div class="col-lg-6 col-sm-5 wow fadeInUp delay-05s">
<div class="form"><font color="#ff0000" size="1"><b>{{$errors->first('nombre', ':message')}}</b></font><input class="input-text" type="text" name="nombre" value="<?=Request::old('nombre', 'Nombre y apellido *');?>" onfocus="if(this.value==this.defaultValue)this.value='';" onblur="if(this.value=='')this.value=this.defaultValue;"><font color="#ff0000" size="1"><b>{{$errors->first('email', ':message')}}</b></font><input class="input-text" type="text" name="email" value="<?=Request::old('email', 'Correo electrónico *');?>" onfocus="if(this.value==this.defaultValue)this.value='';" onblur="if(this.value=='')this.value=this.defaultValue;"><font color="#ff0000" size="1"><b>{{$errors->first('telefono', ':message')}}</b></font><br><input class="input-text" type="text" name="telefono" value="<?=Request::old('telefono', 'Teléfono (incluya código de área) *');?>" onfocus="if(this.value==this.defaultValue)this.value='';" onblur="if(this.value=='')this.value=this.defaultValue;"><font color="#ff0000" size="1"><b>{{$errors->first('asunto', ':message')}}</b></font><input class="input-text" type="text" name="asunto" value="<?=Request::old('asunto', 'Asunto');?>" onfocus="if(this.value==this.defaultValue)this.value='';" onblur="if(this.value=='')this.value=this.defaultValue;"><font color="#ff0000" size="1"><b>{{$errors->first('mensaje', ':message')}}</b></font><textarea class="input-text text-area" cols="0" rows="0" name="mensaje" onfocus="if(this.value==this.defaultValue)this.value='';" onblur="if(this.value=='')this.value=this.defaultValue;"><?=Request::old('mensaje', 'Escriba aquí el mensaje *');?></textarea><font color="#ff0000" size="1"><b>{{$errors->first('g-recaptcha-response', ':message')}}</b></font>{!! Recaptcha::render(['lang'=>'es']) !!}<input class="input-btn" type="submit" value="ENVIAR"></div>
</div></form>
在我的視圖頂部我有一個的var_dump(會話::所有()),這是結果,當百達我提交表單。
array(3) {
["_token"]=>
string(40) "WrQWk9qTH47QrKD6J0Qld8sOhKcUp8xssGpy0F2g"
["_previous"]=>
array(1) {
["url"]=>
string(25) "http://dsnet.dsnet.com.ar"
}
["flash"]=>
array(2) {
["old"]=>
array(0) {
}
["new"]=>
array(0) {
}
}
在PHP工匠路線的執行:列出這是我的結果,所以我檢查了網絡中間件不重複。
的疏遠的是,在我的本地服務器相同的代碼工作,並在所有形式的重定向的結果是:
array(4) {
["_token"]=>
string(40) "4s1rhoydlH7l84Em792N79ymemNjh4Ep6I8WLNSG"
["errors"]=>
object(Illuminate\Support\ViewErrorBag)#177 (1) {
["bags":protected]=>
array(1) {
["default"]=>
object(Illuminate\Support\MessageBag)#178 (2) {
["messages":protected]=>
array(1) {
["email"]=>
array(1) {
[0]=>
string(40) "The email must be a valid email address."
}
}
["format":protected]=>
string(8) ":message"
}
}
}
["flash"]=>
array(2) {
["new"]=>
array(0) {
}
["old"]=>
array(2) {
[0]=>
string(6) "errors"
[1]=>
string(10) "_old_input"
}
}
["_old_input"]=>
array(7) {
["_token"]=>
string(40) "jzCq4CGGgutPJ3qB2ls1rp7uaiHpcra9Aer1vApC"
["nombre"]=>
string(19) "Nombre y apellido *"
["email"]=>
string(21) "Correo electrónico *"
["telefono"]=>
string(38) "Teléfono (incluya código de área) *"
["asunto"]=>
string(6) "Asunto"
["mensaje"]=>
string(26) "Escriba aquí el mensaje *"
["g-recaptcha-response"]=>
string(0) ""
}
}
我記得我有同樣的問題在本地服務器並且我修復了將會話配置文件中的域配置設置爲空,但此解決方案在生產服務器中不起作用。任何想法?