Where do I specify my bindings exactly? It seems I can do it in either of these files.
config/app.php
Inside of 'providers' =>
app/Providers/AppServiceProvider.php
Inside of register()
The AppServiceProvider is the ability for us to provide services to the application. Inside of this file, there's two separate methods, register and boot. Register is used to register those classes that you want to make available inside of your Laravel application that are not dependent upon any other classes.
Service providers are the central place to configure your application. If you open the config/app. php file included with Laravel, you will see a providers array. These are all of the service provider classes that will be loaded for your application.
Providers have two lifecycle methods: register and boot . The register method is where you should add bindings to the service container. The boot method is for performing actions after all service providers have registered their services.
The service providers array is loaded via config/app.php
. This is the only actual place that providers are registered, and is where you should put Service Providers.
AppServiceProvider
is for Laravel-specific services that you've overridden (or actually specified), such as the Illuminate\Contracts\Auth\Registrar
, The HTTP/Console Kernels, and anything you wish to override in Laravel. This is a single service provider, that registers container bindings that you specify.
Really, you could load anything you want here, but there's a bunch of ready-to-go service providers in the app/Providers
directory for you so you don't have to go and make one yourself.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With