这是我的路由代码的模型:
Route::group([
'prefix' => 'account',
], function () {
Route::group([
'middleware' => 'basicAuth',
], function () {
Route::post('profile', 'Account\AccountController@profile');
});
});
Route::group(['prefix' => 'browse'], function () {
Route::post('catalogue', 'Browsing\BrowsingController@catalogue');
});
Kernel.php
:
<?php
namespace App\Http;
use Illuminate\Foundation\Http\Kernel as HttpKernel;
class Kernel extends HttpKernel
{
protected $middleware = [
// Removed code not relevant to problem
];
protected $middlewareGroups = [
// Removed code not relevant to problem
];
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,
'signed' => \Illuminate\Routing\Middleware\ValidateSignature::class,
'throttle' => \Illuminate\Routing\Middleware\ThrottleRequests::class,
'basicAuth' => \App\Http\Middleware\BasicAuth::class
];
}
./account/profile
和./browse/catalogue
都仅在提供了基本身份验证用户凭据的情况下起作用,即使仅account
中指定了基本身份验证。
如何获取基本身份验证以仅应用于其中一个路由组?