did1k did1k - 3 months ago 18
PHP Question

How to pass multiple arguments when running Laravel Tasks on command line?

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


Error message:

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


How to pass multiple arguments in this method?

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