laravel中app/http/kernel.php中$middleware/$middlewareGroups/$routeMiddleware数组的区别

$middleware:应用于全局,所有request都通过其内的中间件;

$middlewareGroups/$routeMiddleware:依照键值,应用于指定路由,例如:

class AwesomeController extends Controller {
 
    public function __construct()
    {
        $this->middleware('csrf');
        $this->middleware('auth', ['only' => 'update'])
    }
 
}
// Single route
$router->get("/awesome/sauce", "AwesomeController@sauce", ['middleware' => 'auth']);
 
// Route group
$router->group(['middleware' => 'auth'], function() {
    // lots of routes that require auth middleware
});

发表评论

电子邮件地址不会被公开。