【问题标题】:Artisan Console command not working in 5.1Artisan Console 命令在 5.1 中不起作用
【发布时间】:2016-08-19 21:42:11
【问题描述】:

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

我做到了:

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

请帮助我,让我知道我做错了什么。

【问题讨论】:

  • 你应该删除javascript标签,因为它与这个问题无关。

标签: php laravel laravel-5 laravel-artisan


【解决方案1】:

您只是忘记了注册您的命令

这部分:https://laravel.com/docs/5.1/artisan#registering-commands.

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

像这样:

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

就是这样。

【讨论】:

    猜你喜欢
    • 2016-10-24
    • 2021-05-10
    • 2020-10-27
    • 2016-04-01
    • 2019-08-18
    • 2015-04-24
    • 2016-04-14
    • 2017-10-10
    • 2015-12-24
    相关资源
    最近更新 更多