我创建了我的中间件,在Kernel.php(middlewareGroups和routeMiddleware数组)中注册了它,但它什么也没做。
Kernel.php / middlewareGroups
"-arg2=\"some spaces\""
Kernel.php / routeMiddleware
'CheckAdmin' => [
\App\Http\Middleware\CheckUserIfAdmin::class,
],
web.php
'CheckAdmin' => \App\Http\Middleware\CheckUserIfAdmin::class,
我的中间件:
Route::group(['middleware' => ['CheckAdmin']], function () {
Route::get('/admin', [
'uses' => 'AdminController@index',
'as' => 'adminpage'
]);
});
答案 0 :(得分:0)
中间件删除endif;
中存在语法错误:
class CheckUserIfAdmin
{
public function handle($request, Closure $next)
{
if(Session::has('ad_id') === false):
return redirect()->route('admin.login');
return $next($request);
}
}