Ad
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
Ad
Answer
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
Ad
source: stackoverflow.com
Related Questions
- → "failed to open stream" error when executing "migrate:make"
- → October CMS Plugin Routes.php not registering
- → OctoberCMS Migrate Table
- → OctoberCMS Rain User plugin not working or redirecting
- → October CMS Custom Mail Layout
- → October CMS - How to correctly route
- → October CMS create a multi select Form field
- → October CMS - Conditionally Load a Different Page
- → How to disable assets combining on development in OctoberCMS
- → October CMS - Radio Button Ajax Click Twice in a Row Causes Content to disappear
- → OctoberCms component: How to display all ID(items) instead of sorting only one ID?
- → In OctoberCMS how do you find the hint path?
- → How to register middlewares in OctoberCMS plugin?
Ad