流明制造:命令

tra*_*jan 26 php laravel lumen

我正在尝试通过命令行在我的Lumen安装中执行代码.在完整的Laravel中,我已经读过你可以通过"make:command"使用命令来实现这一点,但是Lumen似乎不支持这个命令.

反正有没有启用此命令?如果不这样,在Lumen中运行CLI代码的最佳方法是什么?

谢谢

Hie*_* Le 40

您可以artisan像在Laravel中一样使用Lumen中的CLI,但使用较少的内置命令.要查看所有内置命令,请使用php artisanLumen中的命令.

虽然make:commandLumen 没有命令,但您可以创建自定义命令:

  • app/Console/Commands文件夹中添加新的命令类,可以使用framework 命令的示例类模板serve

  • 通过将创建的类添加到文件$commands内的成员来注册自定义命令app/Console/Kernel.php.

除了命令生成之外,您还可以在使用Lumen时使用Laravel docs命令.


小智 8

创建命令类时,请使用以下命令:

serve command

而不是上面描述的关于使用serve command示例的内容


小智 7

这是新命令的模板。您可以将其复制并粘贴到新文件中并开始工作。我在流明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.');
    }
}
Run Code Online (Sandbox Code Playgroud)

然后将其注册在Kernel.php文件中。

/**
* The Artisan commands provided by your application.
*
* @var array
*/
protected $commands = [
   \App\Console\Commands\CommandName::class
];
Run Code Online (Sandbox Code Playgroud)