我最近设置了一些新的中间件作为我正在集成的权限系统的一部分。
我之前已经设置了没有问题的自定义中间件,并且相信我已经遵循了相同的过程,但是这次我为每个添加了我的新中间件的控制器收到以下错误:
Container.php第734行中的ReflectionException: Class App \ Http \ App \ Http \ Middleware \ HasPermissionPermissions不存在
我可以看到它为什么会出现错误,因为该路径不存在 - 但我无法理解它从哪条路走来......
这是我的中间件:
<?php
namespace App\Http\Middleware;
use Closure;
use Auth;
class HasPermissionPermissions
{
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
*/
public function handle($request, Closure $next)
{
if (Auth::user()->hasPermissionTo('permissions'))
{
return $next($request);
}
else
{
flash()->error('You are not authorised to access this route.');
return redirect('/');
}
}
}
My Kernel.php
/**
* The application's route middleware.
*
* @var array
*/
protected $routeMiddleware = [
'auth' => \App\Http\Middleware\Authenticate::class,
'auth.basic' => \Illuminate\Auth\Middleware\AuthenticateWithBasicAuth::class,
'guest' => \App\Http\Middleware\RedirectIfAuthenticated::class,
'application.status' => \App\Http\Middleware\ApplicationCheck::class,
'email.confirmation.check' => \App\Http\Middleware\CheckIfConfirmed::class,
'can' => \Illuminate\Foundation\Http\Middleware\Authorize::class,
'guest' => \App\Http\Middleware\RedirectIfAuthenticated::class,
'throttle' => \Illuminate\Routing\Middleware\ThrottleRequests::class,
'hasPermissionAnnouncements' => \App\Http\Middleware\HasPermissionAnnouncements::class,
'hasPermissionGlobalLog' => \App\Http\Middleware\HasPermissionGlobalLog::class,
'hasPermissionLaravelLog' => \App\Http\Middleware\HasPermissionLaravelLog::class,
'hasPermissionPermissions' => \App\Http\Middleware\HasPermissionPermissions::class,
'hasPermissionUsers' => \App\Http\Middleware\HasPermissionUsers::class,
];
最后,我正在设置控制器:
class PermissionsController extends Controller
{
public function __construct()
{
$this->middleware('auth');
$this->middleware('hasPermissionPermissions');
$this->middleware('email.confirmation.check');
}
如果我删除$this->middleware('hasPermissionPermissions');
它的效果非常好,但我无法看到我的设置方式有何不同!
谁能看到我哪里出错了?
答案 0 :(得分:0)
这是一个很好的问题,这可能是一个简单的想法,我认为你已经做到了这一点,但你确定中间件真的放在中间件目录中吗?
亲切的问候