我知道这是重复的问题。这个问题有很多解决方案,但遗憾的是没有什么对我有用。我查了一下 -
Laravel 5.2 form validation not showing errors?
Laravel 5.2 -> Validation Errors not appearing
ErrorBag is always empty in Laravel 5.2 还有更多...
我正在使用lavavel 5.2.29以及正在采取哪些措施来解决这些已经在其中进行的错误。我的路线,内核已经看起来像其他解决方案。 在kernel.php中
protected $middleware = [
\Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode::class,
\Illuminate\Session\Middleware\StartSession::class,
\Illuminate\View\Middleware\ShareErrorsFromSession::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',
],
];
IN Routes.php
Route::group(['middleware' => ['web']], function () {
Route::get('/','IndexController@index');
Route::get('user/','UserController@showProfile');
Route::match(["get","post"],"user/register",'UserController@register');
Route::match(["get","post"],"user/login",'UserController@login');
});
在用户控制器中 -
$this->validate($this->Request,User::$add_user_rules);
$user_data = Input::all();
$user_data['username'] = explode('@',$user_data["email"])[0];
if(User::create($user_data)){
$this->Request->session()->flash('success', 'Your account has been successfully created. Now please check your email to activate your account.');
}else{
$this->Request->session()->flash('error', 'Oops.. Something went wrong. Please try again !');
}
return redirect("user/register");
并且规则在用户模型中 -
public static $add_user_rules = [
'first_name' => 'required|alpha_dash',
'last_name' => 'alpha_dash',
'email' => 'required|email|unique:users',
'password' => 'required',
"cn_password" => "required|same:password",
];
最后,这是我用来在刀片上显示错误 -
@if (count($errors) > 0)
<div class="alert-message error">
<div><span>Error !</span><br>
@foreach ($errors->all() as $error)
<p>{{ $error }}</p>
@endforeach
</div>
</div>
@endif
现在这段代码中缺少什么。
没有显示任何错误消息。
还有一件事,如果我把路线放在中间件web
之外,一切都很完美。
答案 0 :(得分:0)
默认情况下,在Laravel最新版本5.2 **中,现在位于Web middleware
组中。如果您已在middleware
文件中明确指定了此app\Http\routes.php
组,则应将其删除,这样可以解决您的问题。