找不到Laravel 5.8自定义命令 [英] Laravel 5.8 custom command not found
问题描述
我已经使用工匠创建了一个自定义命令:
I have created a custom command using artisan:
php artisan make:command resetNegotiations
php artisan make:command resetNegotiations
使用以下方法删除已删除的缓存:
Than deleted cache with:
php artisan cache:clear
php artisan cache:clear
但是,如果我尝试运行: php artisan ResetNegotiations ,则会收到错误消息:
But if I try to run: php artisan ResetNegotiations I got the error:
未定义命令"ResetNegotiations".
Command "ResetNegotiations" is not defined.
ResetNegotiations.php 文件存在于 app/Console/Commands
我发现了类似的问题:-命令未定义例外,但不是固定的.
I have found similar questions: - Command is not defined exception but it not fixed mine.
我已将内核更新为 https://laravel.com/docs/5.8/artisan#registering-commands 在app/Console/Kernel.php中,但是...什么也没有.重建缓存后也会出现相同的错误.
I have updated the kernel as https://laravel.com/docs/5.8/artisan#registering-commands in app/Console/Kernel.php but... nothing. The same error also after cache rebuilt.
kernel.php
....
protected $commands = [
Commands\ResetNegotiations::class,
//
];
我缺少什么?
这是命令:
<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
class resetNegotiations extends Command{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'command:name';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Command description';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
//
mail("######@#####.it", "Scheduledartsan ", "Command test");
}
}
推荐答案
protected $ signature ='command:name';
是您在工匠中用来调用命令的方法.只需将签名更改为 protected $ signature ='resetNegotiations';
即可.您发布的工匠命令应在更改后起作用.
protected $signature = 'command:name';
is what you use to call the command in artisan. just change the signature to protected $signature = 'resetNegotiations';
if you want to use that. The artisan command you posted should work after the change.
这篇关于找不到Laravel 5.8自定义命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!