美文网首页我爱编程
laravel中间件学习笔记

laravel中间件学习笔记

作者: 土豆丝呢 | 来源:发表于2018-05-27 22:06 被阅读0次

    路由中间件:

    1,创建中间件

    php artisan make:middleware CheckLogin

    2,注册中间件

    // Within App\Http\Kernel Class...

    protected $routeMiddleware = [

        'auth' => \Illuminate\Auth\Middleware\Authenticate::class,

        'auth.basic' => \Illuminate\Auth\Middleware\AuthenticateWithBasicAuth::class,

        'bindings' => \Illuminate\Routing\Middleware\SubstituteBindings::class,

        'can' => \Illuminate\Auth\Middleware\Authorize::class,

        'guest' => \App\Http\Middleware\RedirectIfAuthenticated::class,

        'throttle' => \Illuminate\Routing\Middleware\ThrottleRequests::class,

    ];

    3,使用中间件

    Route::group(['middleware' => 'check.login'],function(){

            Route::get('tocart','view\cartcontroller@tocart');

            Route::get('order_commit/{product_ids}','view\ordercontroller@toOrderCommit');

            Route::get('toOrderList','view\ordercontroller@toOrderList');

        });

    控制器中间件

    public function __construct()

        {

            $this->middleware('auth',[

                'except'=>['show','create','store']

            ]);

        }

    相关文章

      网友评论

        本文标题:laravel中间件学习笔记

        本文链接:https://www.haomeiwen.com/subject/crmijftx.html