Home >PHP Framework >Laravel >Let's talk about how laravel uses commands to execute scripts
The following tutorial column of Laravel will introduce how to use laravel commands to execute scripts. I hope it will be helpful to everyone!
laravel Use the command to execute the script
1. Generate the console file
php artisan make:console TestConsole --command=laravel:test
2. Edit the business logic in the handle method
<?php namespace App\Console\Commands; use Illuminate\Console\Command; class HelloLaravelAcademy extends Command { /** * The name and signature of the console command. * * @var string */ protected $signature = 'laravel:test {name?}'; /** * The console command description. * * @var string */ protected $description = 'Command description'; /** * Create a new command instance. * * @return void */ public function __construct() { parent::__construct(); } /** * Execute the console command. * * @return mixed */ public function handle() { echo $this->argument("name").PHP_EOL; echo 123; } }
$signature indicates whether to receive parameters, ? indicates that it is not required. arguement receives parameters
execute
php artisan laravel:test php artisan laravel:test xiaoming
[Related recommendations: The latest five Laravel video tutorials】
The above is the detailed content of Let's talk about how laravel uses commands to execute scripts. For more information, please follow other related articles on the PHP Chinese website!