gpt4 book ai didi

php - 拉维尔 4 : Deploy custom artisan command in package

转载 作者:可可西里 更新时间:2023-11-01 13:40:04 24 4
gpt4 key购买 nike

我开发了一些自定义 artisan 命令,以便更轻松地与我的包一起使用。是否可以将 artisan 命令包含到包中以便于部署?如果可以,怎么做?

谢谢。

最佳答案

在你的包结构中设置命令:

<?php namespace App\Artisan;

use Illuminate\Console\Command;

class MyCommand extends Command {

protected $name = 'mypackage:mycommand';

protected $description = 'Nice description of my command.';

public function fire()
{
/// do stuff
}

}

您可以在您的包裹服务提供商中:

<?php namespace App;

use Illuminate\Support\ServiceProvider;
use App\Artisan\MyCommand;

class MyServiceProvider extends ServiceProvider {

public function register()
{
$this->registerMyCommand();

$this->commands('mycommand');
}

private function registerMyCommand()
{
$this->app['mycommand'] = $this->app->share(function($app)
{
return new MyCommand;
});
}

}

诀窍在于行

$this->commands('mycommand');

这告诉 Laravel 将您的命令添加到可用命令的 artisan 列表中。

关于php - 拉维尔 4 : Deploy custom artisan command in package,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22456771/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com