I tried to bind some services in the Laravel AppServiceProvider, but the services weren't bound. I think, that the AppServiceProvider was not even called. Actually, I made a new one and it works.
So my question is, am I doing something wrong? Or was the AppServiceProvider not called?
Default Laravel Service Providers. Let's start with the default service providers included in Laravel, they are all in the app/Providers folder: AppServiceProvider.
Registering ProvidersAll service providers are registered in the config/app. php configuration file. This file contains a providers array where you can list the class names of your service providers. By default, a set of Laravel core service providers are listed in this array.
Service providers can be defined as the central place to configure all the entire Laravel applications. Applications, as well as Laravel's core services, are bootstrapped via service providers. These are powerful tools for maintaining class dependencies and performing dependency injection.
All Laravel routes are defined in your route files, which are located in the routes directory. These files are automatically loaded by your application's App\Providers\RouteServiceProvider . The routes/web.php file defines routes that are for your web interface.
Laravel pre-compiles certain classes that are used on basically every request. This serves the purpose of performance optimization. Files to compile can be specified in config/compile.php
under files
. The default one looks like this:
'files' => [
realpath(__DIR__.'/../app/Providers/AppServiceProvider.php'),
realpath(__DIR__.'/../app/Providers/BusServiceProvider.php'),
realpath(__DIR__.'/../app/Providers/ConfigServiceProvider.php'),
realpath(__DIR__.'/../app/Providers/EventServiceProvider.php'),
realpath(__DIR__.'/../app/Providers/RouteServiceProvider.php'),
],
When running php artisan optimize
when debugging is not enabled (or with the --force
option) Those listed files and other framework classes will be written to storage/framework/compiled.php
.
That means if you change one of those precompiled files, changes won't be applied immediately (if compiled.php
exists) but only after you run php artisan optimize
again or after you run php artisan clear-compiled
to clear the compiled.php
file.
Of course you can also remove the AppServiceProvider
from the list as an alternative solution.
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