Search code examples
phplaravelclassaliaslaravel-11

Understanding class importation and alias management in Laravel 11's new directory structure


I seek guidance on importing classes and managing aliases in Laravel 11, which has introduced a new directory structure. In previous Laravel versions, I would handle these tasks in the app.php configuration file. However, Laravel 11 seems to have a different approach to managing class imports and aliases.

I would appreciate any assistance understanding how to import the Alias Class in this new context.


Solution

  • I've just run into the same problem as you.. searching online I can't find any 'new' way to do it, but fyi the 'old' way still works - just add your own 'aliases' array to config/app.php

    eg:

    'aliases' => Facade::defaultAliases()->merge([
        'MyAlias' => App\SomePath\MyFacade::class,
    ])->toArray(),
    

    and don't forget to import at the top:

    use Illuminate\Support\Facades\Facade;