简体   繁体   中英

Laravel : Fatal error: Uncaught ReflectionException: Class App\Http\Kernel does not exist

so last night i was doing some codes like always(normal class/function code not at all related to kernel or anything) and everything was working perfectly, but today when i wanted to start my coding again this error happend:

Fatal error: Uncaught ReflectionException:
Class App\Http\Kernel does not exist in H:\Hadi\vendor\laravel\framework\src\Illuminate\Container\Container.php:809
Stack trace:
#0 H:\Hadi\vendor\laravel\framework\src\Illuminate\Container\Container.php(809): ReflectionClass->__construct('App\\Http\\Kernel')
#1 H:\Hadi\vendor\laravel\framework\src\Illuminate\Container\Container.php(691): Illuminate\Container\Container->build('App\\Http\\Kernel')
#2 H:\Hadi\vendor\laravel\framework\src\Illuminate\Foundation\Application.php(796): Illuminate\Container\Container->resolve('App\\Http\\Kernel', Array, false)
#3 H:\Hadi\vendor\laravel\framework\src\Illuminate\Container\Container.php(269): Illuminate\Foundation\Application->resolve('App\\Http\\Kernel', Array, false)
#4 H:\Hadi\vendor\laravel\framework\src\Illuminate\Container\Container.php(805): Illuminate\Container\Container->Illuminate\Container\{closure}(Object(Illuminate\Foundation\Application), Array)
#5 H:\Hadi\vendor\laravel\framework\src\Illuminate\Container\Container.php(691): I in H:\Hadi\vendor\laravel\framework\src\Illuminate\Container\Container.php on line 811

OS: Windows 10

PHP Version: 7.4.9

laravel version: 7.30.4

what i already done by reading previous questions:

restore your old composer.lock file
Check composer.json for proper align of "psr-4" it should be child of "autoload" section.
Remove vendor
composer install

php artisan optimize:clear
php artisan config:cache
composer dump-autoload
composer update

Check if console/kernel.php is inside of app-folder,

this is my composer.json

{
    "name": "laravel/laravel",
    "type": "project",
    "description": "The Laravel Framework.",
    "keywords": [
        "framework",
        "laravel"
    ],
    "license": "MIT",
    "require": {
        "php": "7.4.7",
        "anhskohbo/no-captcha": "^3.0",
        "artisaninweb/laravel-soap": "0.3.0.9",
        "econea/nusoap": "dev-master",
        "fideloper/proxy": "^4.0",
        "guzzlehttp/guzzle": "^6.5",
        "hootlex/laravel-friendships": "^1.0",
        "intervention/image": "^2.5",
        "irazasyed/telegram-bot-sdk": "^3.0",
        "laravel/framework": "^7.0",
        "laravel/helpers": "^1.2",
        "laravel/tinker": "^2.0",
        "laravel/ui": "2.0"
    },
    "require-dev": {
        "beyondcode/laravel-dump-server": "^1.0",
        "facade/ignition": "^2.0",
        "filp/whoops": "^2.0",
        "fzaninotto/faker": "^1.4",
        "mockery/mockery": "^1.0",
        "nunomaduro/collision": "^4.1",
        "phpunit/phpunit": "^8.5"
    },
    "config": {
        "optimize-autoloader": true,
        "preferred-install": "dist",
        "sort-packages": true,
        "platform": {
            "php": "7.4.7"
        }
    },
    "extra": {
        "laravel": {
            "dont-discover": [
                "laravel/dusk"
            ]
        }
    },
    "autoload": {
        "psr-4": {
            "App\\": "app/"
        },
        "classmap": [
            "database/seeds",
            "database/factories"
        ]
    },
    "autoload-dev": {
        "psr-4": {
            "Tests\\": "tests/"
        }
    },
    "minimum-stability": "dev",
    "prefer-stable": true,
    "scripts": {
        "post-autoload-dump": [
            "Illuminate\\Foundation\\ComposerScripts::postAutoloadDump",
            "@php artisan package:discover --ansi"
        ],
        "post-root-package-install": [
            "@php -r \"file_exists('.env') || copy('.env.example', '.env');\""
        ],
        "post-create-project-cmd": [
            "@php artisan key:generate --ansi"
        ]
    }
}

and this is my kernel

<?php

namespace App\Console;

use Illuminate\Console\Scheduling\Schedule;
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;
use App\product;

class Kernel extends ConsoleKernel
{

    protected $commands = [

    ];

    protected function schedule(Schedule $schedule)
    {
        $schedule->call('App\Http\Controllers\ProductController@delete')->daily();
    }


    protected function commands()
    {
        $this->load(__DIR__.'/Commands');

        require base_path('routes/console.php');
    }
}

my App\Http\Kernel

<?php

namespace App\Http;

use Illuminate\Foundation\Http\Kernel as HttpKernel;

class Kernel extends HttpKernel
{
    /**
     * The application's global HTTP middleware stack.
     *
     * These middleware are run during every request to your application.
     *
     * @var array
     */
    protected $middleware = [
        \App\Http\Middleware\CheckForMaintenanceMode::class,
        \Illuminate\Foundation\Http\Middleware\ValidatePostSize::class,
        \App\Http\Middleware\TrimStrings::class,
        \Illuminate\Foundation\Http\Middleware\ConvertEmptyStringsToNull::class,
        \App\Http\Middleware\TrustProxies::class,
    ];

    /**
     * The application's route middleware groups.
     *
     * @var array
     */
    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\Localization::class,
        ],

        'api' => [
            'throttle:60,1',
            'bindings',
        ],
    ];

    /**
     * The application's route middleware.
     *
     * These middleware may be assigned to groups or used individually.
     *
     * @var array
     */
    protected $routeMiddleware = [
        'auth' => \App\Http\Middleware\Authenticate::class,
        'auth.basic' => \Illuminate\Auth\Middleware\AuthenticateWithBasicAuth::class,
        'bindings' => \Illuminate\Routing\Middleware\SubstituteBindings::class,
        'cache.headers' => \Illuminate\Http\Middleware\SetCacheHeaders::class,
        'can' => \Illuminate\Auth\Middleware\Authorize::class,
        'guest' => \App\Http\Middleware\RedirectIfAuthenticated::class,
        'signed' => \Illuminate\Routing\Middleware\ValidateSignature::class,
        'throttle' => \Illuminate\Routing\Middleware\ThrottleRequests::class,
        'verified' => \Illuminate\Auth\Middleware\EnsureEmailIsVerified::class,
        'is.admin' => \App\Http\Middleware\IsAdmin::class,
        'locale' => \App\Http\Middleware\Localization::class,
        'ssl' => \App\Http\Middleware\ForceSSL::class,
    ];

    /**
     * The priority-sorted list of middleware.
     *
     * This forces non-global middleware to always be in the given order.
     *
     * @var array
     */
    protected $middlewarePriority = [
        \Illuminate\Session\Middleware\StartSession::class,
        \Illuminate\View\Middleware\ShareErrorsFromSession::class,
        \App\Http\Middleware\Authenticate::class,
        \Illuminate\Session\Middleware\AuthenticateSession::class,
        \Illuminate\Routing\Middleware\SubstituteBindings::class,
        \Illuminate\Auth\Middleware\Authorize::class,
    ];
}

please help me sove this sudden problem

First of all: check if file app/Http/Kernel.php is exists and it has correct namespace and class name (without any cyrilic or etc. characters):

<?php

// Should be 'App\Http'
namespace App\Http;

use Illuminate\Foundation\Http\Kernel as HttpKernel;

// Should be 'Kernel'
class Kernel extends HttpKernel
{
    //
}

If all seems correct - this should be a composer PSR-4 loading bug. Try to remove vendor directory and composer.lock file and run composer install

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM