以前的是5.1版本写的。
现在改成5.6版本。
其中遇到的问题,我会在这个laravel专题中一一指出。
第一个问题是路由时
Route::controller不再支持。
于是,我只好弄成Route:get之类的语法来解决。
第二个问题是中间件如何生效。
写middleware时,不能直接返回view了。。要用response.
return response()->view('user');
然后,将这个中间件,弄进kernel.php里面。
protected $routeMiddleware = [
'auth' => \Illuminate\Auth\Middleware\Authenticate::class,
'auth.basic' => \Illuminate\Auth\Middleware\AuthenticateWithBasicAuth::class,
'bindings' => \Illuminate\Routing\Middleware\SubstituteBindings::class,
'cache.headers' => \Illuminate\Http\Middleware\SetCacheHeaders::class,
'can' => \Illuminate\Auth\Middleware\Authorize::class,
'guest' => \App\Http\Middleware\RedirectIfAuthenticated::class,
'throttle' => \Illuminate\Routing\Middleware\ThrottleRequests::class,
'middleware.xxx' => \App\Http\Middleware\XXXMiddleware::class,
];
最后,不管是在controller的__construct里,还是在routers/web.php里,加入中间件缩写。
Route::get('/xxx','xxxController@getIndex')->middleware('middleware.xxx')->name('user.xxx');
public function __construct(){
$this->middleware('middleware.xxx');
}