2016-04-26 61 views
2

我是laravel新手。我试图在我的测试项目中创建一个自定义的artisan命令来创建表格。我遵循this link,但我的命令不在工匠列表中。事件我尝试了在该链接中给出的相同示例,但它也没有工作。我不知道为什么会发生。Artisan控制台命令不工作在5.1

我这样做:

1)运行此命令php artisan make:console SendEmails

2)将完整的类代码app/Console/Commands/SendEmails.php文件

<?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'))); 
    } 
} 

请帮帮我,让我知道我在做什么错误。

+1

您应该删除'javascript'标签,因为它与此问题无关。 –

回答

4

你只是忘了注册您的命令

该零件:https://laravel.com/docs/5.1/artisan#registering-commands

打开app/Console/Kernel.php并在$commands数组中添加命令类。

这样的:

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

就是这样。

+0

感谢它的工作......... –