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

A brief analysis of how laravel partially excludes middleware

藏色散人
Release: 2021-10-20 15:32:26
forward
2721 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:
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
Latest Issues
Composer cannot install laravel
From 1970-01-01 08:00:00
0
0
0
Laravel Space/laravel-backup cannot be installed
From 1970-01-01 08:00:00
0
0
0
Laravel 5.1 Login laravel comes with it No more
From 1970-01-01 08:00:00
0
0
0
Why thinkphp has better performance than laravel?
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template