laravel5.5-第9章-自动加载command laravel5.5-第9章-自动加载command

2023-07-04

一、下载 laravel 5.5

composer create-project laravel/laravel=5.5.* laravel5.5_command

切换目录

cd laravel5.5_command

二、自动加载 command

创建 command

php artisan make:command SayHello

修改创建的文件:app/Console/Commands/SayHello.php

protected $signature = 'say-hello';

protected $description = 'Hi Boy';

public function handle()
{
   $this->info('Hello Boy');
}

执行 help

php artisan help say-hello

https://file.lulublog.cn/images/3/2023/07/twppo77JPp46f7F7JP54757Uj7pW75.jpg

执行 command

php artisan say-hello

自动加载代码:app/Console/Kernel.php

protected function commands()
{
   $this->load(__DIR__.'/Commands');

   require base_path('routes/console.php');
}
阅读 429