UpdateCommentNickName.php 578 B

12345678910111213141516171819202122232425
  1. <?php
  2. use app\common\model\Comment;
  3. use think\facade\Db;
  4. use think\migration\Seeder;
  5. class UpdateCommentNickName extends Seeder
  6. {
  7. /**
  8. * Run Method.
  9. *
  10. * Write your database seeder using this method.
  11. *
  12. * More information on writing seeders is available here:
  13. * http://docs.phinx.org/en/latest/seeding.html
  14. */
  15. public function run()
  16. {
  17. $comments = Comment::with(['user'])->select();
  18. foreach($comments as $item) {
  19. $item->nick_name = $item->user->nick_name ?? '';
  20. $item->save();
  21. }
  22. }
  23. }