Home  >  Article  >  Backend Development  >  laravel控制器使用中间件

laravel控制器使用中间件

WBOY
WBOYOriginal
2016-06-23 13:13:031271browse


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

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