Home > PHP Framework > Laravel > body text

A brief analysis of how laravel partially excludes middleware

藏色散人
Release: 2021-10-20 15:32:26
forward
2514 people have browsed it

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 () {

    });});
Copy after login

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

        }

    }
Copy after login

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!

Related labels:
source:learnku.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!