[英]ReflectionException - Middleware class does not exist Laravel 5.5
I know that I am not the first one with such a problem. 我知道我不是第一个遇到这种问题的人。 I have read all the existing information on Stackoverflow and other sources but it could not solve my problem that I always will get a ReflectionException
Class App\\Http\\Middleware\\xxx does not exist
. 我已经阅读了有关Stackoverflow和其他来源的所有现有信息,但它无法解决我的问题,我总是会得到一个ReflectionException
Class App\\Http\\Middleware\\xxx does not exist
。
<?php
namespace App\Http\Middleware\xxx;
use Closure;
class xxx
{
public function handle($request, Closure $next)
{
return $next($request);
}
}
No joke, this is really my class. 不开玩笑,这真的是我的班级。 I have renamed it to xxx
to avoid typo. 我已将其重命名为xxx
以避免拼写错误。
All my routes will pass the web
and admin
Middleware: 我的所有路线都将通过web
和admin
中间件:
Route::middleware(['web', 'admin'])->group(function() {
And this is my /app/Http/Kernel.php
: 这是我的/app/Http/Kernel.php
:
protected $middlewareGroups = [
'web' => [
\App\Http\Middleware\EncryptCookies::class,
\Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class,
\Illuminate\Session\Middleware\StartSession::class,
// \Illuminate\Session\Middleware\AuthenticateSession::class,
\Illuminate\View\Middleware\ShareErrorsFromSession::class,
\App\Http\Middleware\VerifyCsrfToken::class,
\Illuminate\Routing\Middleware\SubstituteBindings::class,
\App\Http\Middleware\xxx::class,
],
xxx.php
and it location is App\\Http\\Middleware\\
. 文件名为xxx.php
,其位置为App\\Http\\Middleware\\
。 I also tried to modify my composer.json: 我也尝试修改我的composer.json:
"autoload": {
"classmap": [
"database/seeds",
"database/factories",
"App/Http/Middleware/xxx.php"
],
which caused following warning: 导致以下警告:
Warning: Ambiguous class resolution, "App\Http\Middleware\xxx\xxx" was found in both "$baseDir . '/app/Http/Middleware/xxx.php" and "/code/App/Http/Middleware/xxx.php", the first will be used.
First, change namespace to: 首先,将名称空间更改为:
namespace App\Http\Middleware;
Then remove "App/Http/Middleware/xxx.php"
from composer.json
and run composer du
然后从composer.json
删除"App/Http/Middleware/xxx.php"
并运行composer du
You also, need to remove web middleware from the routes file if you're using 5.2.27 and higher: 如果您使用的是5.2.27及更高版本,还需要从路径文件中删除Web中间件 :
Route::middleware(['admin'])->group(function() {
将名称空间更改为 -
namespace App\Http\Middleware;
You may have cached files in bootstrap/cache
directory. 您可能在bootstrap/cache
目录中有缓存的文件。 Delete those and composer dumpautoload again. 再次删除那些和作曲家dumpautoload。
If that too fails, delete your entire vendor directory and delete composer.lock
and then run composer install
. 如果这也失败了,删除整个供应商目录并删除composer.lock
,然后运行composer install
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.