Laravel-permission: ReflectionException: Class App\Http\Middleware\ClearanceMiddleware does not exist

Created on 1 Jul 2017  路  5Comments  路  Source: spatie/laravel-permission

this error get displayed from time to time not all time don't know why could you please clarify this
ReflectionException: Class App\Http\Middleware\ClearanceMiddleware does not exist in C:\wamp64\www\blog\vendor\laravel\framework\src\Illuminate\Container\Container.php:729

<?php

namespace App\Http\Middleware;

use Closure;
use Illuminate\Support\Facades\Auth;


class ClearanceMiddleware {
    /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure  $next
     * @return mixed
     */
    public function handle($request, Closure $next) {        
        if (Auth::user()->hasPermissionTo('Administer roles & permissions')) //If user has this //permission
        {
            return $next($request);
        }
    }
}

Most helpful comment

For me I had to add the middleware to Kernel.php and then it worked (I added the admin middleware).
In: app/Http/Kernel.php ->

protected $routeMiddleware = [
        'auth' => \App\Http\Middleware\Authenticate::class,
        'auth.basic' => \Illuminate\Auth\Middleware\AuthenticateWithBasicAuth::class,
        ........
        'verified' => \Illuminate\Auth\Middleware\EnsureEmailIsVerified::class,
        'admin' => \App\Http\Middleware\Admin::class,
    ];

All 5 comments

This problem is not related to this package.

Is the name of your file correct? Try dumping the autoloader.

i did the following and it's working

  • composer dump-autoload to pop up the error

  • renamed the file clearance under app\Http\Middleware to ClearanceMiddleware

Sorry for the intrusion i know it's not a package related

by the way thank you so much for this great package really helped me a lot in my project

What solved this problem I encountered the same problem

For me I had to add the middleware to Kernel.php and then it worked (I added the admin middleware).
In: app/Http/Kernel.php ->

protected $routeMiddleware = [
        'auth' => \App\Http\Middleware\Authenticate::class,
        'auth.basic' => \Illuminate\Auth\Middleware\AuthenticateWithBasicAuth::class,
        ........
        'verified' => \Illuminate\Auth\Middleware\EnsureEmailIsVerified::class,
        'admin' => \App\Http\Middleware\Admin::class,
    ];

In your file, app/Http/Kernel.php your should have these two following line regarding laravel-permission in the $routeMiddleware array

// Role & Permission
'role' => \Spatie\Permission\Middlewares\RoleMiddleware::class,
'permission' => \Spatie\Permission\Middlewares\PermissionMiddleware::class,
Was this page helpful?
0 / 5 - 0 ratings

Related issues

NattananWs picture NattananWs  路  3Comments

tripex picture tripex  路  3Comments

MichalKrakow picture MichalKrakow  路  4Comments

holymp2006 picture holymp2006  路  4Comments

ergonomicus picture ergonomicus  路  3Comments