S. Wasta
S. Wasta

Reputation: 638

Laravel Task: How can I pass params to use in method?

I'm setting up a new Task with Laravel and this task calls to a method from other class, this method needs a parameter.

I have been reading doc from Laravel this says I have to include the param in $signature among {} And I did it.

protected $signature = 'cmd:taskTest {id}';

In my handle function (in command class)

    public function handle()
    {
        WebController::downloadFile(); // downloadFile needs param
    }

And my method, which is called by handle.

public static function downloadFile($warehouseId){
//do something
}

I have tried writing this in prompt:

php artisan cmd:taskTest 1

It returned an error because it needs the id to find all information in database about this id.

To create the command I ran this:

php artisan make:command

Upvotes: 1

Views: 539

Answers (1)

Chin Leung
Chin Leung

Reputation: 14941

You can retrieve it with the argument method.

WebController::downloadFile($this->argument('id'));

For more information: https://laravel.com/docs/5.5/artisan#command-io

Upvotes: 2

Related Questions