Home > Article > PHP Framework > A brief analysis of how laravel partially excludes middleware
The following tutorial column will introduce you to the laravel partial exclusion middleware, I hope it will be helpful to you!
A method to handle logged in users and unlogged usersapi file
// 用户端接口 Route::prefix('client')->group(function () { Route::apiResource('applys', 'ApplysController'); //需要登录授权的接口 //multiauth:member_api 中间件全局注册 Route::group(['middleware' => ['multiauth:member_api', 'check.member']], function () { });});
private $flag; public function __construct(Request $request) { $this->flag = false; //判断是否有令牌 if(array_key_exists('authorization',$request->header())){ $this->middleware( ['multiauth:member_api', 'check.member']); }else{ $this->flag = true; $this->middleware( ['multiauth:member_api', 'check.member'],['except' => 'index']); } }
The above is the detailed content of A brief analysis of how laravel partially excludes middleware. For more information, please follow other related articles on the PHP Chinese website!