Lumen 5.2 Class ” Not found

A quick tip when using Lumen 5.2, if you try and include a feature you may get the error Class’Log’ not found for example. This is because be default, unlike Laravel facades are not loaded to save on resource and increase the framework speed.

If  you need to use one of the built in Faades then you need to un-comment $app->withFacades(); in the /bootstrap/app.php file:

From:

// $app->withFacades();

To:

$app->withFacades();

Its worth noting this will add a lot of extra load onto your Lumen app so its worth commenting out the facades you don’t want in the /src/Application.php file.

public function withFacades()
    {
        Facade::setFacadeApplication($this);

        if (! static::$aliasesRegistered) {
            static::$aliasesRegistered = true;

            //class_alias('Illuminate\Support\Facades\Auth', 'Auth');
            //class_alias('Illuminate\Support\Facades\Cache', 'Cache');
            //class_alias('Illuminate\Support\Facades\DB', 'DB');
            //class_alias('Illuminate\Support\Facades\Event', 'Event');
            //class_alias('Illuminate\Support\Facades\Gate', 'Gate');
            class_alias('Illuminate\Support\Facades\Log', 'Log');
            //class_alias('Illuminate\Support\Facades\Queue', 'Queue');
            //class_alias('Illuminate\Support\Facades\Schema', 'Schema');
            //class_alias('Illuminate\Support\Facades\URL', 'URL');
            //class_alias('Illuminate\Support\Facades\Validator', 'Validator');
        }
    }

Now you can simply call the Facade in any of your controllers like so:

use Log;
Log::info('something happened');

Leave a Reply

Your email address will not be published. Required fields are marked *