在改造一个支付流程,新的流程加入了一个新的数据表字段,但是这个新的字段需要通过计算来填充,所以为了兼容历史数据,必须将已有的数据行重新计算一遍该字段。

这时使用 laravel console 命令就非常方便,因为可以共用 .env 中的数据库连接配置,以及定义好的 model。

自动创建 console 命令类

php artisan make:command YourCommand

这时会看到目录

app/Console/Commands

下多了一个新的命令类,在 handle 中写计算逻辑即可。

console 命令类的几个必填项

  • signature 命令名及参数指定
  • description 命令描述
  • handle 即逻辑部分

在 console 中输出日志

$this->info('Display this on the screen');

参考

https://laravel.com/docs/5.6/artisan#introduction

相关文章:

  • 2021-07-17
  • 2022-02-10
  • 2022-02-10
  • 2022-02-10
  • 2022-02-10
  • 2021-12-12
  • 2022-01-06
猜你喜欢
  • 2022-12-23
  • 2021-04-07
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-11-17
相关资源
相似解决方案