下面由laravel教程栏目带大家介绍laravel怎么用命令来执行脚本,希望对大家有所帮助!
laravel 使用命令执行脚本
1.生成console文件
php artisan make:console TestConsole --command=laravel:test
2.handle方法中编辑业务逻辑
<?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为是否接收参数,?表示非必须。 arguement接收参数
执行
php artisan laravel:test php artisan laravel:test xiaoming
【相关推荐:最新的五个Laravel视频教程】
以上就是聊聊laravel怎么用命令来执行脚本的详细内容,更多请关注php中文网其它相关文章!
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号