我是新來的流明,我試圖讓角色中間件從一個例子流明文檔工作: http://lumen.laravel.com/docs/middleware#middleware-parameters流明角色中間件缺少參數
但只要我中間件添加到路由像這樣:
$app->get('/', ['middleware' => 'role:editor', 'uses' => '[email protected]']);
我得到的錯誤:
at Application->Laravel\Lumen\{closure}('2', 'Missing argument 3 for App\Http\Middleware\RoleMiddleware::handle()', '/Users/peter/app/Http/Middleware/RoleMiddleware.php', '17', array('request' => object(Request), 'next' => object(Closure))) in RoleMiddleware.php line 17
當我刪除中間件一切正常
$app->get('/', ['uses' => '[email protected]']);
在app.php:
$app->middleware([
Illuminate\Cookie\Middleware\EncryptCookies::class,
Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class,
Illuminate\Session\Middleware\StartSession::class,
Illuminate\View\Middleware\ShareErrorsFromSession::class,
Laravel\Lumen\Http\Middleware\VerifyCsrfToken::class,
App\Http\Middleware\RoleMiddleware::class
]);
應用程序\ HTTP \中間件\ RoleMiddleware.php:
<?php
namespace App\Http\Middleware;
use Closure;
class RoleMiddleware
{
public function handle($request, Closure $next, $role) // <-line 17
{
if (! $request->user()->hasRole($role)) {
// Redirect...
}
return $next($request);
}
}
希望有人能幫助
顯示RoleMiddleware類 –
添加了RoleMiddleware類 – Peter