Laravel - AppServiceProvider is not called

laravel

Solution

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.

Problem

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?

Original source