Home>Article>PHP Framework> A brief analysis of how laravel partially excludes middleware

A brief analysis of how laravel partially excludes middleware

John Lennon
John Lennon forward
2021-10-20 15:32:11 2453browse

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 users

A brief analysis of how laravel partially excludes middleware

api file

// 用户端接口 Route::prefix('client')->group(function () { Route::apiResource('applys', 'ApplysController'); //需要登录授权的接口 //multiauth:member_api 中间件全局注册 Route::group(['middleware' => ['multiauth:member_api', 'check.member']], function () { });});

Controller settings

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']); } }

Related recommendations:The latest five Laravel video tutorials

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!

Statement:
This article is reproduced at:learnku.com. If there is any infringement, please contact admin@php.cn delete