Why php artisan run all commands in the folder Commands when I create a model for example ? Did I made something wrong ?
-
have you tried `php artisan make:model Models/Modelname` – JEJ Nov 16 '21 at 09:34
-
Its just an example php artisan tinker run the commands too, why ? – Eloise85 Nov 16 '21 at 10:12
-
1Why do you believe it runs all commands? what are the symptons etc. – mrhn Nov 16 '21 at 10:14
-
I see the $this->info('blablabla') displaying before tinker runs. – Eloise85 Nov 16 '21 at 13:52
2 Answers
Laravel will initialize
all the commands (User defined and Default commands) whenever you run any command in laravel application.
Which means don't perform any operation in __construct
method of the commands.
For Example:
If you are performing any Databse operation in __construct
method of custom command it will perform Databse operation no matter what command to ran.
So Move all the logics and operations to handle
method of command.
I have faced the same issue back in the day You can see the github issue to clarify.

- 5,896
- 4
- 30
- 43
Artisan is the command line interface included with Laravel. Artisan exists at the root
of your application as the artisan script and provides a number of helpful commands that can assist you while you build your application.
See more at : https://laravel.com/docs/8.x/artisan

- 502
- 3
- 14