当前位置:Gxlcms > PHP教程 > laravel控制器使用中间件

laravel控制器使用中间件

时间:2021-07-01 10:21:17 帮助过:13人阅读

官方文档写的比较简单,只用如下就行了,但你使用过程中是会报错的,因为还没建立对应关系

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,];

人气教程排行