I have recently set up some new middleware as part of a permissions system I am integrating.
I have previously setup custom middleware without issue and believe I have followed the same process, but this time I am getting the following error for every controller I have added my new middleware to:
ReflectionException in Container.php line 734: Class App\Http\App\Http\Middleware\HasPermissionPermissions does not exist
I can see why it is getting an error, as that path does not exist - but I cannot understand where it is getting that path from...
Here is my middleware:
<?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,
];
And finally, the controller I am setting this up in:
class PermissionsController extends Controller
{
public function __construct()
{
$this->middleware('auth');
$this->middleware('hasPermissionPermissions');
$this->middleware('email.confirmation.check');
}
If I remove $this->middleware('hasPermissionPermissions');
it works perfectly, but I can't see how I have set it up any different!
Can anyone see where I am going wrong?
composer dump-autoload
would do – Cerlincomposer dump-autoload -o
– JameshasPermissionPermissions
tohasPermission.permissions
, and see if that works. – patricus