Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

laracoft's avatar
Level 27

How to add an alias for blade?

  1. In composer.json, we can define extra.laravel.aliases which then becomes available in blade.
  2. However, each time I do that, I must remove and require my package again.
  3. Is there a way to make the alias available in blade without have to perform step 2?
  4. Or is there a command that I can run to "refresh" all available aliases for blade?
0 likes
8 replies
RemiM's avatar

Instead of manually removing and re-requiring the package, you can use the composer dump-autoload command to regenerate the Composer autoloader files and refresh the aliases without needing to re-run composer require.

Snapey's avatar

Or are you talking about making facades available in blade files?

laracoft's avatar
Level 27

I'm talking about being able to write {{ Abcde::method(...) }}, Abcde is known as an alias in blade, correct?

Snapey's avatar

@laracoft you can put @use(Abcde::class) at the top of your blade files

Ive not come across adding things to composer to do this

martinbean's avatar

Abcde is known as an alias in blade, correct?

@laracoft No. That’s just a facade alias. It’s not something Blade-specific.

Sinnbeck's avatar

If we are talking about facades you can add this to the bottom of your config/app.php file to create aliases

'aliases' => Facade::defaultAliases()->merge([
        'Abcde' => \Some\Real\Thing::class,
    ])->toArray(),
laracoft's avatar
laracoft
OP
Best Answer
Level 27

I have never used @use(...) before yet all the Abcde::method1() Fghijk::method2() worked.

The command that solves the problem is php artisan package:discover, it reads from composer.json's extra.laravel.aliases and registers them.

Thanks all!

Please or to participate in this conversation.