Reputation:
Just migrated my Laravel app from a local environment to a online development environment on a remote server. After this migration I am getting an error:
ReflectionException thrown with message "Class App\Http\MiddleWare\NotUser does not exist"
I've deleted the vendor
folder, as well as composer.lock
and ran composer update
. Also cleared bootstrap/cache
and also tried runningphp artisan config:clear
.
Purged all cache/*
files from storage. Whenever I attempt to log in to the dashboard, I receive the error that middleware does not exist.
app/Http/Middleware/NotUser.php
<?php
namespace App\Http\Middleware;
use Closure;
class NotUser
{
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
*/
public function handle($request, Closure $next)
{
# This middleware prevents anyone who is not an admin from accessing given route or controller
# apply by using it in the constructor, $this->middleware('is.admin');
if ($request->user()->role->name === 'user') {
return back()->with('error', __('Access denied'));
}
return $next($request);
}
}
app/Http/Kernel.php
protected $routeMiddleware = [
...
'not.user' => \App\Http\MiddleWare\NotUser::class
];
routes/web.php
Route::group(['prefix' => 'admin', 'middleware' => ['not.user', 'auth']], function () { ... }
This works fine on locally hosted environment. I had no problems. After I switched to a development environment I started receiving this error and I have no idea what's causing this.
Upvotes: 2
Views: 5187
Reputation: 14268
The namespace is case sensitive I believe, so change this:
protected $routeMiddleware = [
...
'not.user' => \App\Http\MiddleWare\NotUser::class
];
to this:
protected $routeMiddleware = [
...
'not.user' => \App\Http\Middleware\NotUser::class
];
Notice the capital W
in Middleware
.
Upvotes: 4