Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

lopatin's avatar

Why 'php artisan inspire' doesn't work?

Hello, I have a project written in Laravel v10 I need to add some custome artisan commands. I found out a file 'routes/console.php', there is a default/example of artisan command

Artisan::command('inspire', function () {
    $this->comment(Inspiring::quote());
})->purpose('Display an inspiring quote');

So I try in my console to run this command

php artisan inspire

but as a result I see an error message on terminal

ERROR Command "inspire" is not defined.

I have tried to clear cache, rerun application, try a debug function in console.php file (something like dd('test');). Nothing helps... Please help me. Why inspire command doesn't work?

P.S. When I run php artisan list, there is no inspire comman registered...

P.S. P.S. My purpose is recreate some existing command

if ('production' === App::environment()) {
    Artisan::command('migrate:fresh', function () {
        $this->comment('You are not allowed to do this in production!');
    })->describe('Override default command in production.');
}
0 likes
2 replies
martinbean's avatar

@lopatin You’d be better off hooking into Artisan events and throwing an error if someone tries to run unwanted commands in production, rather than creating commands that call commands:

public function handle(CommandStarting $event): void
{
    if ($this->app->environment('production')) {
        $disabledCommands = [
            'artisan:fresh',
        ];

        if (in_array($event->command, $disabledCommands)) {
            throw new RuntimeException(
                message: sprintf('Cannot run command [%s] in production.', $command),
            );
        }
    }
}
lopatin's avatar

@martinbean super, I will try it, but I would still like to figure out why it doesn’t work in my case (php artisan inspire).

Please or to participate in this conversation.