Gur*_*Bob 16 php laravel artisan
在shell中我可以像这样创建数据库迁移(例如):
./artisan migrate:make --table="mytable" mymigration
Run Code Online (Sandbox Code Playgroud)
使用Artisan :: call()我无法弄清楚如何传递非参数参数(在本例中为"mymigration").我尝试了以下代码的许多变体:
Artisan::call('db:migrate', ['--table' => 'mytable', 'mymigration'])
Run Code Online (Sandbox Code Playgroud)
有人有任何想法吗?我一直在使用shell_exec('./ artisan ......')但我对这种方法并不满意.
Bow*_*wer 17
Artisan::call('db:migrate', ['' => 'mymigration', '--table' => 'mytable']) 应该管用.
顺便说一句,db:migrate不是一个开箱即用的工匠命令.你确定这是对的吗?
iko*_*iko 14
在laravel 5.1中,当您从PHP代码调用Artisan命令时,可以使用/不设置值来设置选项.
Artisan::call('your:commandname', ['--optionwithvalue' => 'youroptionvalue', '--optionwithoutvalue' => true]);
Run Code Online (Sandbox Code Playgroud)
在这种情况下,在你的工匠命令内;
$this->option('optionwithvalue'); //returns 'youroptionvalue'
$this->option('optionwithoutvalue'); //returns true
Run Code Online (Sandbox Code Playgroud)
orr*_*rrd 10
如果您使用Laravel 5.1或更高版本,解决方案会有所不同.现在你需要做的是你需要知道命令签名中赋予参数的名称.您可以使用php artisan help命令名称在命令shell中找到参数的名称.
我想你想问一下"make:migration".因此,例如php artisan help make:migration向您显示它接受名为"name"的参数.所以你可以这样称呼:Artisan::call('make:migration', ['name' => 'foo' ]).
| 归档时间: |
|
| 查看次数: |
18911 次 |
| 最近记录: |