我正在尝试通过命令行在Lumen安装中执行代码。在完整的Laravel中,我读到你可以通过"make: command“使用命令来实现这一点,但是Lumen似乎不支持这个命令。
有什么方法可以激活这个命令吗?如果失败了,在Lumen中从CLI运行代码的最佳方式是什么?
谢谢
发布于 2018-10-08 02:31:03
这是一个新命令的模板。您只需将其复制并粘贴到新文件中,即可开始工作。我在流明5.7.0上测试了它
<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
class CommandName extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'commandSignature';
/**
* 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()
{
$this->info('hello world.');
}
}
然后在Kernel.php文件中注册它。
/**
* The Artisan commands provided by your application.
*
* @var array
*/
protected $commands = [
\App\Console\Commands\CommandName::class
];
发布于 2015-11-23 19:39:58
在创建命令类时,请使用以下命令:
<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
而不是上面描述的使用serve command
示例
https://stackoverflow.com/questions/30251065
复制相似问题