lundi 5 février 2018

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.

<?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.

All my routes will pass the web and admin Middleware:

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

And this is my /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,
    ],  

  • File is named xxx.php and it location is App\Http\Middleware\.
  • Namespace is correct
  • composer dump-autoload will not solve the problem

I also tried to modify my 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.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire