ReflectionException - 中间件类不存在Laravel 5.5

时间:2018-02-05 08:02:12

标签: php laravel laravel-5

我知道我不是第一个遇到这种问题的人。我已经阅读了有关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.

3 个答案:

答案 0 :(得分:3)

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

namespace App\Http\Middleware;

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

如果您使用5.2.27及更高版本,还需要remove web middleware from the routes file

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

答案 1 :(得分:2)

将名称空间更改为 -

namespace App\Http\Middleware;

答案 2 :(得分:1)

您可能在INSERT INTO tbl_vacancy_poojai (vc_serial_no,vc_poojai_name,vc_poojai_amount,vc_poojai_time, vc_book_date,vc_vacancy,vc_bok_poj,vc_type,vc_block) VALUES ( (SELECT vc_serial_no FROM tbl_tot_vacancy_poojai), (SELECT vc_poojai_name FROM tbl_tot_vacancy_poojai), (SELECT vc_poojai_amount FROM tbl_tot_vacancy_poojai), (SELECT vc_poojai_time FROM tbl_tot_vacancy_poojai), '04/02/2018', (SELECT vc_vacancy FROM tbl_tot_vacancy_poojai), ('04/02/2018'+(SELECT vc_serial_no FROM tbl_tot_vacancy_poojai)), (SELECT vc_type FROM tbl_tot_vacancy_poojai),1) 目录中有缓存文件。再次删除那些和作曲家dumpautoload。

如果失败,请删除整个供应商目录并删除bootstrap/cache,然后运行composer.lock