【发布时间】:2019-06-27 12:38:28
【问题描述】:
刚刚将我的 Laravel 应用程序从本地环境迁移到远程服务器上的在线开发环境。在此迁移之后,我收到一个错误:
ReflectionException thrown with message "Class App\Http\MiddleWare\NotUser does not exist"
我已删除 vendor 文件夹以及 composer.lock 并运行 composer update。还清除了bootstrap/cache 并尝试运行php artisan config:clear。
从存储中清除所有 cache/* 文件。每当我尝试登录仪表板时,都会收到中间件不存在的错误。
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 () { ... }
这在本地托管环境中运行良好。我没有问题。切换到开发环境后,我开始收到此错误,但我不知道是什么原因造成的。
【问题讨论】:
标签: laravel