Date
1 min read

Laravel Aliases

Ever wonder how some classes do not require a full namespace to be called in a blade view? i.e.

{{ Auth::id() }}

Instead of:

{{ \Illuminate\Support\Facades\Auth::id() }}

Laravel has a configuration file config/app.php that maps class namespaces to an alias i.e.

// ...

/*
|--------------------------------------------------------------------------
| Class Aliases
|--------------------------------------------------------------------------
|
| This array of class aliases will be registered when this application
| is started. However, feel free to register as many as you wish as
| the aliases are "lazy" loaded so they don't hinder performance.
|
*/

'aliases' => [

	'App' => Illuminate\Support\Facades\App::class,
	'Arr' => Illuminate\Support\Arr::class,
	'Artisan' => Illuminate\Support\Facades\Artisan::class,
	'Auth' => Illuminate\Support\Facades\Auth::class,
	
	// ...

],

You might also like...

  • Read article

    Exporting large amounts of data in Laravel

    An opinionated approach on how best to handle exporting large amounts of data in Laravel using commands and queues.

  • Read article

    How to save markdown using an editor and render it using Laravel

    How to setup a Laravel Markdown editor and convert the markdown to HTML easy.

  • Read article

    Laravel update multiple rows with different values

    Discover efficient techniques for updating multiple rows with unique values in Laravel. Explore step-by-step instructions and practical examples to streamline your database operations.

Let's work together 🤝

Line
Christopher Kelker

Chriscreates