在命令行上运行Laravel Tasks时如何传递多个参数? [英] How to pass multiple arguments when running Laravel Tasks on command line?

查看:590
本文介绍了在命令行上运行Laravel Tasks时如何传递多个参数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个Task类,其中的方法需要多个参数:

I created a Task class with method that needs multiple arguments:

class Sample_Task
{
    public function create($arg1, $arg2) {
        // something here
    }
}

但是似乎工匠只能得到第一个论点:

But it seems that artisan only gets the first argument:

php artisan sample:create arg1 arg2

错误消息:

Warning: Missing argument 2 for Sample_Task::create()

如何在此方法中传递多个参数?

How to pass multiple arguments in this method?

推荐答案

class Sample_Task
{
    public function create($args) {
       $arg1 = $args[0];
       $arg2 = $args[1];
        // something here
    }
}

这篇关于在命令行上运行Laravel Tasks时如何传递多个参数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆