gpt4 book ai didi

php - ReflectionException - 中间件类不存在 Laravel 5.5

转载 作者:可可西里 更新时间:2023-10-31 22:09:01 25 4
gpt4 key购买 nike

我知道我不是第一个遇到这样问题的人。我已经阅读了关于 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);
}
}

不是开玩笑,这真的是我的课。我已将其重命名为 xxx 以避免打字错误。

我所有的路由都会通过 webadmin 中间件:

Route::middleware(['web', 'admin'])->group(function() {  

这是我的/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,位置为App\Http\Middleware\
  • 命名空间正确
  • composer dump-autoload 不能解决问题

我还尝试修改我的 composer.json:

"autoload": {
"classmap": [
"database/seeds",
"database/factories",
"App/Http/Middleware/xxx.php"
],

导致以下警告:

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.

最佳答案

首先,将命名空间更改为:

namespace App\Http\Middleware;

然后从 composer.json 中删除 "App/Http/Middleware/xxx.php" 并运行 composer du

你也需要remove web middleware from the routes file如果您使用的是 5.2.27 及更高版本:

Route::middleware(['admin'])->group(function() { 

关于php - ReflectionException - 中间件类不存在 Laravel 5.5,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48618046/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com