雨燕 - CnSwift

敏捷开发- agile development

Laravel中间件

Laravel中间件

自定义中间件

kernel.php

1
2
3
4
5
6
7
8
9
protected $routeMiddleware = [
'auth' => \App\Http\Middleware\Authenticate::class,
'auth.basic' => \Illuminate\Auth\Middleware\AuthenticateWithBasicAuth::class,
'can' => \Illuminate\Foundation\Http\Middleware\Authorize::class,
'guest' => \App\Http\Middleware\RedirectIfAuthenticated::class,
'throttle' => \Illuminate\Routing\Middleware\ThrottleRequests::class,
// 自定义中间件
'admin.login' => \App\Http\Middleware\AdminLogin::class,
];

创建中间件

artisan命令

1
php artisan make:middleware AdminLogin

使用中间件

routes.php

1
2
3
4
5
Route::group(['profile' => 'admin', 'namespace' => 'Admin', 'middleware' => ['admin.login']], function () {
Route::get('index', 'IndexController@index');
Route::get('articlelist', 'IndexController@articlelist');
Route::resource('article', 'ArticleController');
});
感谢赞赏.

Welcome to my other publishing channels