下面由Laravel教程欄目帶大家介紹laravel怎么用命令來執(zhí)行腳本,希望對大家有所幫助!
laravel 使用命令執(zhí)行腳本
1.生成console文件
php artisan make:console TestConsole --command=laravel:test
2.handle方法中編輯業(yè)務邏輯
<?php namespace AppConsoleCommands; use IlluminateConsoleCommand; 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為是否接收參數(shù),?表示非必須。 arguement接收參數(shù)
執(zhí)行
php artisan laravel:test php artisan laravel:test xiaoming
【