'Fatal Error Laravel: Uncaught ReflectionException when i view my Site

I have the following error when i view my site.

My Error:

Fatal error: Uncaught ReflectionException: Class log does not exist in /home/vagrant/Code/in10km/vendor/laravel/framework/src/Illuminate/Container/Container.php:741> Stack trace: #0 /home/vagrant/Code/in10km/vendor/laravel/framework/src/Illuminate/Container/Container.php(741): ReflectionClass->__construct('log') #1 /home/vagrant/Code/in10km/vendor/laravel/framework/src/Illuminate/Container/Container.php(631): Illuminate\Container\Container->build('log', Array) #2 /home/vagrant/Code/in10km/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(674): Illuminate\Container\Container->make('log', Array) #3 /home/vagrant/Code/in10km/vendor/laravel/framework/src/Illuminate/Container/Container.php(842): Illuminate\Foundation\Application->make('log') #4 /home/vagrant/Code/in10km/vendor/laravel/framework/src/Illuminate/Container/Container.php(805): Illuminate\Container\Container->resolveClass(Object(ReflectionParameter)) > #5 /home/vagrant/Code/in10km/vendor/laravel/framework/src/Illuminate/Container/Container.php(774): Il in /home/vagrant/Code/in10km/vendor/laravel/framework/src/Illuminate/Container/Container.php on line 741

My Composer.json file is like this

{
    "name": "laravel/laravel",
    "description": "The Laravel Framework.",
    "keywords": ["framework", "laravel"],
    "license": "MIT",
    "type": "project",
    "require": {
        "php": ">=5.5.9",
        "laravel/framework": "5.1.*",
        "doctrine/dbal": "v2.4.2",
        "swiftmailer/swiftmailer": "^5.4",
        "guzzlehttp/guzzle": "~5.3|~6.0",       
        "chrisbjr/api-guard": "^2.3",
        "serverfireteam/panel": "1.3.*",
        "laravel/socialite": "^2.0"

    },
    "require-dev": {
        "fzaninotto/faker": "~1.4",
        "mockery/mockery": "0.9.*",
        "phpunit/phpunit": "~4.0",
        "phpspec/phpspec": "~2.1"
    },
    "autoload": {
        "files": [
            "app/Http/helpers.php",
            "app/Support/helpers.php"
        ],
        "classmap": [
            "database"
        ],
        "psr-4": {
            "App\\": "app/"
        }
    },
    "autoload-dev": {
        "classmap": [
            "tests/TestCase.php"
        ]
    },
    "scripts": {
        "post-install-cmd": [
            "php artisan clear-compiled",
            "php artisan optimize"
        ],
        "pre-update-cmd": [
            "php artisan clear-compiled"
        ],
        "post-update-cmd": [
            "php artisan optimize"
        ],
        "post-root-package-install": [
            "php -r \"copy('.env.example', '.env');\""
        ],
        "post-create-project-cmd": [
            "php artisan key:generate"
        ]
    },
    "config": {
        "preferred-install": "dist"
    }
}

Anyone help me how to get rid of this error and view my site successfully.



Solution 1:[1]

Delete all files in bootstrap/cache/ then run:

composer dump-autoload -o

Solution 2:[2]

I had a similar issue. I found that to really dig down into the issue, you need to modify the Illuminate/Container/Container.php file, as suggested here at the third from the top.

<?php

namespace {
    use Monolog\Logger as Monolog;
    class log extends Illuminate\Log\Writer {
        function __construct()
        {
            $this->monolog = new Monolog("local");
        }
    }
}

namespace Illuminate\Container {

    use Closure;
    use ArrayAccess;
    use ReflectionClass;
    use ReflectionMethod;
    use ReflectionFunction;
    use ReflectionParameter;
    use InvalidArgumentException;
    use Illuminate\Contracts\Container\Container as ContainerContract;
    use Illuminate\Contracts\Container\BindingResolutionException as BindingResolutionContractException;


    class Container implements ArrayAccess, ContainerContract
    {

Modify it as the code suggests, and add an additional closing bracket to the bottom. This will allow it to display the error that it otherwise has been unable to display and thus be able to fix your problem!

Solution 3:[3]

Delete vendor file and then run composer update

Solution 4:[4]

I found the solution, in my routes i don't called exactly the name of the Controller

Example:

Route::get('/endpoint', 'Namebadcontroller@function');

// Correct name of route
Route::get('/endpoint', 'NameBadController@function');

And run the follow commands:

composer dump-autoload -o

php artisan clear-compiled php artisan optimize

Solution 5:[5]

The issue might originate from a package that is not (yet) downloaded in your vendor folder (with all installed vendor packages) In that case composer dump-autoload -o does not fix your issue.

Check you composer.json and composer.lock.

I added main into my branch from a GIT repo.

composer.json and composer.lock did not match!

The resolution was to recover composer.json and composer.lock from main and readded all changes from my branch manually.

Just to be sure I also removed my vendor folder.

Running composer install (re)installed all packages stored in composer.lock and added all (newer) not yet installed.

Notice that running composer update might fix the issue, but alse updates packages that perhaps may not be updated.

Solution 6:[6]

Try the command composer dump-autoload -o.

I used it to overcome the problem: 'Uncaught ReflectionException'.

Good luck!

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 JoSSte
Solution 2 Nick
Solution 3 AlmoDev
Solution 4 Gustavo Marquez
Solution 5 Bitpatroon
Solution 6 Philippe Signoret