下面由Laravel教程栏目带大家介绍关于laravel 局部排除中间件,希望对大家有所帮助!
一个方法处理已登录的的用户 和 未登录的用户
api文件
// 用户端接口 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']); } }