欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  后端开发

laravel控制器使用中间件

程序员文章站 2022-06-06 22:48:05
...
官方文档写的比较简单,只用如下就行了,但你使用过程中是会报错的,因为还没建立对应关系
public function __construct(){    $this->middleware('wechatapi');}

打开app/Http/Kernel.php

protected $routeMiddleware = [    'auth' => \App\Http\Middleware\Authenticate::class,    'auth.basic' => \Illuminate\Auth\Middleware\AuthenticateWithBasicAuth::class,    'guest' => \App\Http\Middleware\RedirectIfAuthenticated::class,    'throttle' => \Illuminate\Routing\Middleware\ThrottleRequests::class,    'wechatapi'=>\App\Http\Middleware\WechatApi::class,];