carlosmora's avatar

config\app 'aliases' array still in use?

Some time ago, AFAIK, the 'aliases' in app\config array was a way to add Facades to Laravel apps. If I look into version 10 docs, there is no single mention of it or it's behavoir. Does it has bee deprecated in any way? I'm updating a version 5.5 app to 10 and the use of Facades in aliases (IMHO) breaks some general conventions.

KR,

Carlos

0 likes
5 replies
vincent15000's avatar

Aliases are still in use in Laravel 10.

If you have a look at the app.php code, you will see this.

'aliases' => Facade::defaultAliases()->merge([
    // 'Example' => App\Facades\Example::class,
])->toArray(),

Then if you have a look at the Facade class in the vendor files, you will find the defaultAliases() function which returns all default aliases.

public static function defaultAliases()
{
    return collect([
        'App' => App::class,
        'Arr' => Arr::class,
        'Artisan' => Artisan::class,
        'Auth' => Auth::class,
        'Blade' => Blade::class,
        'Broadcast' => Broadcast::class,
        'Bus' => Bus::class,
        'Cache' => Cache::class,
        'Config' => Config::class,
        'Cookie' => Cookie::class,
        'Crypt' => Crypt::class,
        'Date' => Date::class,
        'DB' => DB::class,
        'Eloquent' => Model::class,
        'Event' => Event::class,
        'File' => File::class,
        'Gate' => Gate::class,
        'Hash' => Hash::class,
        'Http' => Http::class,
        'Js' => Js::class,
        'Lang' => Lang::class,
        'Log' => Log::class,
        'Mail' => Mail::class,
        'Notification' => Notification::class,
        'Password' => Password::class,
        'Process' => Process::class,
        'Queue' => Queue::class,
        'RateLimiter' => RateLimiter::class,
        'Redirect' => Redirect::class,
        'Request' => Request::class,
        'Response' => Response::class,
        'Route' => Route::class,
        'Schema' => Schema::class,
        'Session' => Session::class,
        'Storage' => Storage::class,
        'Str' => Str::class,
        'URL' => URL::class,
        'Validator' => Validator::class,
        'View' => View::class,
        'Vite' => Vite::class,
    ]);
}
1 like
carlosmora's avatar

Hi Vincent! Thanks for your answer. Yes, they are there, but there is no mention of aliases in the documentation, so probably it's there for compatibility. My thoughts were "if it's not in docs, then should be a deprecation warning somewhere that i didn't see or something", so... here I am.

They seems to be silently set aside, but I'd like to find what's the policy regarding them.

KR

Carlos

1 like
vincent15000's avatar

@carlosmora No, the aliases aren't set aside, they are only imported from the Facade class in order to simplify the app.php file.

1 like
Snapey's avatar

You can add your own. If that was not the intention then this section in app.php would be pulled completely.

Don't forget also, real-time facades.

2 likes
thinkverse's avatar
Level 15

The core facade aliases were removed from the skeleton config in Laravel 9 and moved internally since most users didn't ever change them. For package developers starting with Laravel 5.5 you didn't have to make end-users register your aliases manually anymore either.

And as @snapey also mentioned, with read-time facades there isn't really a need to even register custom facades from your application.

But you are of course free to add back the default aliases in app.php if that's how you want to config. Keep in mind though that in case of a facade update where Laravel either adds or removes an alias. You'll have to manually change the config again to reflect that. Facade::defaultAliases() protects you from that by abstracting it away.

2 likes

Please or to participate in this conversation.