我爱编程

laravel中间件学习笔记

2018-05-27  本文已影响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']

        ]);

    }

上一篇下一篇

猜你喜欢

热点阅读