laravel 5.8 你好 我在路由目录中添加了一个新路由文件,名称为“ admin.php” 会话刷新和错误验证在此路由文件中不起作用 但在web.php会话Flash中,验证错误效果很好
这是RouteServiceProvider中的map方法
public function map()
{
$this->mapApiRoutes();
$this->mapWebRoutes();
$this->mapAdminRoutes();
}
mapAdminRoutes方法
protected function mapAdminRoutes()
{
Route::prefix('admin')->middleware(['auth','admin'])
->namespace($this->namespace."\Admin")
->group(base_path('routes/admin.php'));
}
我在admin.php路由中不使用任何中间件
我尝试过
在mapApiRoutes方法中删除->middleware(['auth','admin'])
note:session.flash和admin.php路由的错误验证在web.php中效果很好
答案 0 :(得分:1)
您需要为app/Http/Kernel.php
App\Http\Kernel
protected $middlewareGroups = [
'admin' => [
\Illuminate\Session\Middleware\StartSession::class,
\Illuminate\View\Middleware\ShareErrorsFromSession::class,
],
];
为了简洁起见,我剥离了其他中间件,
web
和api
都保留了下来,
您可以看到web
组应用了StartSession
和ShareErrorsFromSession
中间件,因此对于新的路由文件,您也必须手动进行操作
希望这会有所帮助