Put your code inside runningInConsole
use Illuminate\Support\Facades\App;
if (! App::runningInConsole()) {
// your code
}
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Hello,
I'm facing a problem with a query in a service constructor. I use this service to connect an API, and in this constructor I get the token which is in my database.
This way, I don't have to fetch the token every times I want to fetch data from this API in other services.
However, when I pushed my code on a dev server, php artisan migrate can't run because table which store this token is not yet created.
I found that the problem come from Laravel service providers. They get instantiated when running artisan.
It's very annoying because I have to put away this usefull token initalialization form constructor and call it every time I want to use my service.
Any one has an idea to handle this ? Am I doing something wrong ?
Please or to participate in this conversation.