ThinkChat2.0新版上线,更智能更精彩,支持会话、画图、阅读、搜索等,送10W Token,即刻开启你的AI之旅 广告
1.定义中间件(admin_api_auth)。 ``` Route::group(['prefix' => 'v1/admin_api','middleware'=>'admin_api_auth'], function ($router) { //登录 Route::post('auth/login/login', 'v1\LoginController@login'); }); ``` 2.找到app\Http\Kernel.php 定义admin_api_auth中间件。 ``` protected $routeMiddleware = [ 'admin_api_auth' => \Modules\AuthAdmin\Http\Middleware\AdminApiAuth::class, ]; ``` 3.创建Modules\AuthAdmin\Http\Middleware\AdminApiAuth.php文件。 ``` php artisan module:make-middleware AdminAuth AuthAdmin ``` ``` <?php namespace Modules\AuthAdmin\Http\Middleware; use Closure; use Illuminate\Http\Request; use Illuminate\Support\Facades\Auth; use Modules\AuthAdmin\Models\Admin as AdminModel; class AdminApiAuth { /** * Handle an incoming request. * php artisan module:make-middleware AdminAuth Admin * @param \Illuminate\Http\Request $request * @param \Closure $next * @return mixed */ public function handle(Request $request, Closure $next) { $route_data = $request->route(); $url = str_replace($route_data->getAction()['prefix'] . '/',"",$route_data->uri); $url_arr = [ 'auth/login/login', ]; if(!in_array($url,$url_arr)){ /*$AdminModel = new AdminModel(); if(!$AdminModel->where(['id'=>$request->header('Authorization')])->count()){ } return response()->json(['code'=>1001,'msg'=>'请登录!'],200);*/ } return $next($request); } } ``` 视频链接 ```[youku] XNDU0MDQ5NTUxMg ```