I looked at this case, and it seems that it is not easy. If you use singleton in your custom Provider, it will finally be overridden by the default provider (deferred), so it seems like it is not.
After verifying that the simple approach does not work, you need to analyze in this case what happens when Laravel registers this command.
So, in your case, you are first looking for command.app.name - you see it in Illuminate\Foundation\Providers\ArtisanServiceProvider , and there is a registerAppNameCommand method that you would probably override.
So now you are looking for an entry of ArtisanServiceProvider to see where it was launched - you see it in the Illuminate\Foundation\Providers\ConsoleSupportServiceProvider in the $providers property (which you probably want to change).
So, you should look for entries of ConsoleSupportServiceProvider , and you see it in config/app.php .
So what you need to do in this case:
- Change
config/app.php - change Illuminate\Foundation\Providers\ConsoleSupportServiceProvider to your own ConsoleSupportServiceProvider - In your custom version, you should go from
\Illuminate\Foundation\Providers\ConsoleSupportServiceProvider , but change $providers from Illuminate\Foundation\Providers\ArtisanServiceProvider to your ArtisanServiceProvider - finally, create a custom
ArtisanServiceProvider that will expand from \Illuminate\Foundation\Providers\ArtisanServiceProvider , where you redefine registerAppNameCommand using your own class in singleton
Using this method, you will achieve your goal (I checked that the user class will be used with the php artisan app:name command).
Alternatively, you may want to create your own ArtisanServiceProvider remove 'AppName' => 'command.app.name', from $devCommands and use your specialized service provider, as you showed where you register your singleton, but I have not tried this approach .
Marcin nabiałek
source share