【发布时间】:2018-10-23 11:49:48
【问题描述】:
我仍在使用 Laravel 5.3。 (我很快就会升级,但在那之前我一直坚持使用这个版本)。我创建了几个命令并将它们注册到我的 kernal.php 文件中。这是一个例子:
class Kernel extends ConsoleKernel
{
protected $commands = [
// one off commands
Commands\Sproj\Command1::class,
Commands\Sproj\Command2::class,
Commands\Sproj\Command3::class,
Commands\Sproj\Command4::class,
// scheduled commands
Commands\ScheduledCommand1::class,
Commands\ScheduledCommand2::class,
Commands\ScheduledCommand3::class,
];
protected function schedule(Schedule $schedule)
{
$schedule->command('ScheduledCommand1')->dailyAt('14:00');
$schedule->command('ScheduledCommand2')->dailyAt('15:00');
$schedule->command('ScheduledCommand3')->dailyAt('16:00');
}
protected function commands()
{
require base_path('routes/console.php');
}
}
其中一个命令的示例如下:
class Command1 extends Command
{
protected $signature = 'sproj:command1';
protected $description = 'Command Example';
public function __construct()
{
parent::__construct();
}
public function handle()
{
echo 'Do something here';
}
}
我想执行“一次性”命令之一,所以我使用类似php artisan sproj:command1的命令
这确实有效,但它也在执行我创建的所有其他命令。即使我运行诸如php artisan cache:clear 之类的内置命令,我的所有自定义命令都在运行
我做错了吗?
【问题讨论】:
-
你用的是同一个签名吗?
-
不,签名都是不同的,尽管它们都以 sproj 开头:
-
除非您提供真实的命令示例,否则我认为这将无法重现,因此您不太可能获得任何帮助。
-
很遗憾,我不允许上传任何真实代码。这是违反公司政策的。不管怎么说,还是要谢谢你。我会继续努力的。