2014-02-11 42 views
2

,我們可以在Laravel的包中創建一個命令4.1鍵入文檔says如何爲Laravel 4包創建命令?

php artisan command:make AssignUsers --bench="vendor/package" 

但似乎沒有工作,我得到了以下錯誤消息:

[RuntimeException的]
「--bench」選項不存在。

有沒有辦法爲Laravel 4軟件包創建命令?

回答

5

我使用的標準工匠命令來創建一個命令到我的包:

php artisan command:make CreateUsers \ 
    --path="workbench/vendor/package/src/vendor/package" 

之後,使其提供在消費類應用程序,我不得不添加以下到我的包的的ServiceProvider(以啓動方法):

$this->app->bind('vendor::command.user.create', function($app) { 
    return new UserCreateCommand(); 
}); 
$this->commands(array(
    'vendor::command.user.create' 
)); 

之後,一切都會正常工作。

+3

非常感謝Rubens。真的幫助我。你能否讓我知道你在哪裏找到這個命令的綁定語法?我無法在任何地方找到它。 – Leng

+1

棒極了,謝謝魯本斯! –

-1

當你運行你會SSE的參數列表爲make

PHP的工匠命令:make --help

你應該看到類似

Usage: 
command:make [--command[="..."]] [--path[="..."]] [--namespace[="..."]] name 

Arguments: 
name     The name of the command. 

Options: 
--command    The terminal command that should be assigned. 
--path    The path where the command should be stored. 
--namespace   The command namespace. 
--help (-h)   Display this help message. 
--quiet (-q)   Do not output any message. 
--verbose (-v|vv|vvv) Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug 
--version (-V)  Display this application version. 
--ansi    Force ANSI output. 
--no-ansi    Disable ANSI output. 
--no-interaction (-n) Do not ask any interactive question. 
--env     The environment the command should run under. 

你從輸出中可以看出沒有參數替補

pro每辦法做到這一點是

php artisan command:make AssignUsers 

然後去/app/start/artisan.php並添加以下行

Artisan::add(new AssignUsers); 

然後編輯在/app/commands/AssignUsers.php生成的文件 將$ name的值更改爲AssignUsers ,就完成了。