Laravel 11 - Providers and Alias in app.php Does anyone have a good tutorial on how to install through NPM and register providers and aliases? It is not part of app.php anymore and not sure how to install packages like toastr.
THanks
Hi @artisticre
There is a post wrote by @poptech where he explain very well how works now the process
https://laracasts.com/discuss/channels/laravel/how-to-add-middleware-aliases-in-laravel-11
I will make an example with the library Excel of Maatwebsite
Laravel 10:
// config/app.php
return [
'aliases' => Facade::defaultAliases()->merge([
'Excel' => Maatwebsite\Excel\Facades\Excel::class,
])->toArray(),
];
Laravel 11:
// bootstrap/app.php
return Application::configure(basePath: dirname(__DIR__))
$middleware->alias([
'Excel' => Maatwebsite\Excel\Facades\Excel::class,
]);
})->create();
IMPORTANT
Remember Laravel 11 supports Laravel 10 structure, so if you are updating from Laravel 10 to Laravel 11 you can still using the old structure.
$middleware->alias is the middleware alias. It has nothing to do with Facade's alias.
The method of registering short Facade alias is the same as Laravel 10. Add 'aliases' to config/app.php yourself.
Before that, Facade can be used without adding 'aliases'.
Forget short Facade. Always use a full namespace.
// good
use Illuminate\Support\Facades\Auth;
auth()->user()
{{ Auth::user()->name }} in Blade only
// bad
use Auth;
\Auth::user()
@puklipo Could you give an example of the following
Add 'aliasses' to config/app.php yourself.
config/app.php now looks as follows:
return Application::configure(basePath: dirname(__DIR__))
->withRouting(
web: __DIR__.'/../routes/web.php',
commands: __DIR__.'/../routes/console.php',
health: '/up',
)
->withMiddleware(function (Middleware $middleware) {
})
->withExceptions(function (Exceptions $exceptions) {
//
})
->create();
Where would one add the 'aliases'?
packages are auto-discovered
That's done with the composer package. Not npm.
Make composer package.
Please sign in or create an account to participate in this conversation.