[英]session errors on Laravel 5.2 validator while in 'web' middleware
Validation errors are not being stored on my Laravel 5.2 application (new installation, not upgraded). 验证错误未存储在我的Laravel 5.2应用程序中(新安装,未升级)。 In addition,
$old('value')
is not retaining the values after validation fail. 此外,验证失败后,
$old('value')
不会保留这些值。
All my routes are contained in the web
middleware, and I also tried moving the web middleware contents to the global $middleware
variable in Kernel.php
. 我所有的路由都包含在
web
中间件中,并且我还尝试将Web中间件的内容移至Kernel.php
的全局$middleware
变量。
I have also attempted to clear my route cache in artisan and include use Illuminate\\Foundation\\Validation\\ValidationException
at the top of my controller to see if i could make it work. 我还尝试清除工匠中的路线缓存,并在控制器顶部添加了
use Illuminate\\Foundation\\Validation\\ValidationException
,以查看是否可以使它正常工作。 It seems like the validation is processing, it's just not storing it in the session/throwing the exception. 似乎验证正在处理中,只是不将其存储在会话中/引发异常。 I say this because
Session::flash
is also not working in the same way and the user remember me feature doesn't seem to be storing as long as the cookie says it does, as I am required to re-log in after about 6 hours. 我之所以这样说,是因为
Session::flash
也无法以相同的方式工作,并且用户记得我的功能似乎并没有像cookie所说的那样存储,因为我需要在大约6点后重新登录小时。
Routes Setup (I have "regular" public routes and then a staff route: 路线设置(我有“常规”公共路线,然后有员工路线:
Route::group(['middleware' => ['web']], function () {
// Basic Route...
$this->get('/', 'PublicController@index');
// Staff Route...
Route::group(['middleware' => 'staff'], function () {
$this->get('/staffpanel', 'Staff\StaffController@showStaffPanel');
});
});
Kernel.php Kernel.php
namespace App\Http;
use Illuminate\Foundation\Http\Kernel as HttpKernel;
class Kernel extends HttpKernel
{
protected $middleware = [
\Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode::class,
\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,
];
/**
* 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',
],
];
/**
* The application's route middleware.
*
* These middleware may be assigned to groups or used individually.
*
* @var array
*/
protected $routeMiddleware = [
'staff' => \App\Http\Middleware\Staff::class,
'auth' => \App\Http\Middleware\Authenticate::class,
'auth.basic' => \Illuminate\Auth\Middleware\AuthenticateWithBasicAuth::class,
'guest' => \App\Http\Middleware\RedirectIfAuthenticated::class,
'throttle' => \Illuminate\Routing\Middleware\ThrottleRequests::class,
];
}
Validation snippet: 验证代码段:
protected function validatorMakeCategory(array $data) {
return Validator::make($data, [
'name' => 'required|max:50|unique:categories',
'description' => 'max:255',
]);
}
public function postCreateCategory(Request $request) {
$validator = $this->validatorMakeCategory($request->all());
if ($validator->fails()) {
$this->throwValidationException(
$request, $validator
);
}
}
Errors/Session in views (neither of which show): 视图中的错误/会话(均未显示):
@if(Session::has('message'))
<p class="alert {{ Session::get('alert-class', 'alert-info') }}">{{ Session::get('message') }}</p>
@endif
@if (count($errors) > 0)
<div class="alert alert-danger">
<ul>
@foreach ($errors->all() as $error)
<li>{{ $error }}</li>
@endforeach
</ul>
</div>
@endif
我遇到了同样的问题,我决定删除受保护的$middleware
中的\\App\\Http\\Middleware\\VerifyCsrfToken::class
和我的路由从Route::group(['middleware' => ['web']]
,function (),但我不知道以后是否会有任何问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.