我的自定义中间件出了问题。它不起作用。我已在Kernel.php中注册了它,routeMiddleware
数组。
protected $routeMiddleware = [
'auth' => \Illuminate\Auth\Middleware\Authenticate::class,
'auth.basic' => \Illuminate\Auth\Middleware\AuthenticateWithBasicAuth::class,
'bindings' => \Illuminate\Routing\Middleware\SubstituteBindings::class,
'can' => \Illuminate\Auth\Middleware\Authorize::class,
'guest' => \App\Http\Middleware\RedirectIfAuthenticated::class,
'throttle' => \Illuminate\Routing\Middleware\ThrottleRequests::class,
// 'jwt.auth' => Tymon\JWTAuth\Middleware\GetUserFromToken::class,
'jwt.refresh' => Tymon\JWTAuth\Middleware\RefreshToken::class,
'upload.file' => \App\Http\Middleware\Upload::class,
'admin.settings' => \App\Http\Middleware\AdminChange::class,
];
在我的中间,我使用dd
来打印......
class AdminChange
{
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
*/
public function handle($request, Closure $next)
{
dd('i\'m here');
config(['auth.providers.users.model' => '\App\Models\Useradmin::class']);
return $next($request);
}
}
而且,我的api团体就是这样。
$api = app('Dingo\Api\Routing\Router');
$api->group([
'version' => 'v1',
'namespace' => 'App\Http\Controllers\Api',
],function($api){
$api->group([
'middleware'=>['admin.settings'],
'prefix'=>'ad'
],function($api){
include_once(base_path('routes/v1/admin/notice.php'));
});
$api->group([
'middleware' => ['api.auth']
],function($api){
});
});
我尝试将别名 admin.settings 重命名为其他名称,但仍无效。
我无法我在这里,似乎中间件无效。有人帮忙吗?