聊聊​laravel怎么用命令来执行脚本

下面由laravel教程栏目带大家介绍laravel怎么用命令来执行脚本,希望对大家有所帮助!

laravel 使用命令执行脚本

1.生成console文件

 php artisan make:console TestConsole --command=laravel:test

2.handle方法中编辑业务逻辑

<?php namespace AppConsoleCommands; use IlluminateConsoleCommand; class HelloLaravelAcademy extends Command {     /**      * The name and signature of the console command.      *      * @var string      */     protected $signature = &#39;laravel:test {name?}&#39;;     /**      * The console command description.      *      * @var string      */     protected $description = &#39;Command description&#39;;     /**      * 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为是否接收参数,?表示非必须。 arguement接收参数

执行

 php artisan laravel:test    php artisan laravel:test xiaoming

【相关推荐:laravel

以上就是聊聊​

© 版权声明
THE END
喜欢就支持一下吧
点赞13 分享