Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Artisan: "Command not found"

So I try to add a Command with

php artisan command:make MailSendCommand

The file MailSendCommand.php is created. I edited it to this:

class MailSendCommand extends Command {

    protected $name = 'command:send-mail';

    protected $description = 'Send mails to the users.';


    public function __construct()
    {
        parent::__construct();
    }


    public function fire()
    {
        $this->info('Befehl wird ausgeführt' );
    }
...

In my file start/artisan.php I added

Artisan::add(new MailSendCommand);

but when I enter 'php artisan command:send-mail' it says:

Command "command:send-mail" is not defined.

It just worked on my Home PC (XAMPP) but not on my live server (PHP 5.5.15 (cgi-fcgi))

'php artisan clear:cache' and 'php artisan dump-autoload' did not help.

like image 367
ya-cha Avatar asked Dec 12 '25 01:12

ya-cha


1 Answers

Go to app/Console/Kernel.php and add the class to the commands variable. It would look something like:

class Kernel extends ConsoleKernel
{
    /**
     * The Artisan commands provided by your application.
     *
     * @var array
     */
    protected $commands = [
        Commands\MyCustomCommand::class,
    ];

    /**
     * Define the application's command schedule.
     *
     * @param  \Illuminate\Console\Scheduling\Schedule  $schedule
     * @return void
     */
    protected function schedule(Schedule $schedule)
    {
        // $schedule->command('inspire')
        //          ->hourly();
    }
}

Here i added MyCustomCommand as a valid artisan command. Check it is among available commands executing:

php artisan list
like image 98
EliuX Avatar answered Dec 14 '25 03:12

EliuX



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!