adam.harvie's avatar

Facade error "Class 'App' not found" after upgrade to Lumen 5.2

Hi all,

I recently upgraded from Lumen 5.0 to 5.2. I have Facades enabled and a helper class that uses the App facade to resolve a custom service provider. This worked until the upgrade and now I get a "Class 'App' not found" error.

The helper class is basically as follows:

<?php namespace App\Helpers;

    use App;
    use Log;

    class FileHelper {
        // snip

        // this function called by a public static function in the same class via self::filesByType
        private static function filesByType($store, $type) {
            $fly = App::make('fly', [$store]);
            //do something with $fly
        }

        //snip
    }

The Log facade works fine, but App is causing an error. I tried a composer dumpautoload but no change.

I checked that vendor/illuminate/support/Facades/App.php exists.

Any idea what's going on, or should I use another method of invoking the service container here?

Thanks!

0 likes
4 replies
adam.harvie's avatar

Ok, I see the 'App' facade is no longer registered in Laravel\Lumen\Application. Not sure why.

 /**
     * Register the facades for the application.
     *
     * @return void
     */
    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\Validator', 'Validator');
        }
    }
adam.harvie's avatar
adam.harvie
OP
Best Answer
Level 1

I re-added the class alias after withFacades() in bootstrap/app.php, which works. Not sure if there's a better solution.

$app->withFacades();
//re-add the App facade removed in 5.2:
class_alias('Illuminate\Support\Facades\App', 'App');
1 like

Please or to participate in this conversation.