Code Star Code Star - 7 months ago 23
PHP Question

Artisan Console command not working in 5.1

I am new in laravel. I was trying to make a custom

artisan
command for creating tables in my test project.I followed this link but my command was not on the artisan list.Event I tried same example given in that link but its also not worked. I dont know why its happening.

I DID THIS:

1) Run this command
php artisan make:console SendEmails


2) Put complete class code in
app/Console/Commands/SendEmails.php
file

<?php

namespace App\Console\Commands;

use App\User;
use App\DripEmailer;
use Illuminate\Console\Command;

class SendEmails extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'email:send {user}';

/**
* The console command description.
*
* @var string
*/
protected $description = 'Send drip e-mails to a user';

/**
* The drip e-mail service.
*
* @var DripEmailer
*/
protected $drip;

/**
* Create a new command instance.
*
* @param DripEmailer $drip
* @return void
*/
public function __construct(DripEmailer $drip)
{
parent::__construct();

$this->drip = $drip;
}

/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
$this->drip->send(User::find($this->argument('user')));
}
}


Please help me let me know what I am doing wrong.

Answer

You just forgot to Register your command.

This part: https://laravel.com/docs/5.1/artisan#registering-commands.

Open app/Console/Kernel.php and add you command class in $commands array.

like this :

protected $commands = [
    Commands\SendEmails::class
];

That's it.