There is no problem not worth solving, and no technology not worth learning!

In Laravle 6, set the refactoring of mysql field type JSON value (implemented based on the helper function arr )

最终生成的结构如下所示,是一个对象,字段名称为:extra

1. Existing code implementation


if ($themeInstallationTask->setting_migrations) {
	$settingMigrations = $themeInstallationTask->setting_migrations;
}
$settingMigrations[] = [
	'file' => $availableVersion . '/' . $this->migrateSettingsDataFile,
	'exec_at' => now()->utc()->toDateTimeString()
];
$themeInstallationTask->setting_migrations = $settingMigrations;
$themeInstallationTask->save();


2. The final generated structure is as follows, which is an array with the field name: SETTING_MIGRATIONS


[
  {
    "file": "v2.0.15-rc.6/migrate_settings_data.php",
    "exec_at": "2022-10-31 09:45:06"
  },
  {
    "file": "v2.0.15-rc.7/migrate_settings_data.php",
    "exec_at": "2022-10-31 09:45:06"
  },
  {
    "file": "v2.0.15/migrate_settings_data.php",
    "exec_at": "2022-10-31 09:45:06"
  },
  {
    "file": "v2.0.17-rc.0/migrate_settings_data.php",
    "exec_at": "2022-10-31 09:45:06"
  }
]


3. Decide to adjust the name of the adjustment field as extra, and include the value of the setting_migrations field. The code is adjusted as follows, based on the helper function ar.


$extra = $themeInstallationTask->extra;
if (Arr::has($extra, 'setting_migrations')) {
	$settingMigrations = Arr::get($extra, 'setting_migrations');
}
$settingMigrations[] = [
	'file' => $file,
	'exec_at' => now()->utc()->toDateTimeString()
];
Arr::set($extra, 'setting_migrations', $settingMigrations);
$themeInstallationTask->extra = $extra;
$themeInstallationTask->save();


4. The final generated structure is as follows, is an object, and the field name is EXTRA. as shown in Figure 1

最终生成的结构如下所示,是一个对象,字段名称为:extra
Figure 1

{
  "setting_migrations": [
    {
      "file": "v2.0.15-rc.6/migrate_settings_data.php",
      "exec_at": "2022-10-31 09:45:06"
    },
    {
      "file": "v2.0.15-rc.7/migrate_settings_data.php",
      "exec_at": "2022-10-31 09:45:06"
    },
    {
      "file": "v2.0.15/migrate_settings_data.php",
      "exec_at": "2022-10-31 09:45:06"
    },
    {
      "file": "v2.0.17-rc.0/migrate_settings_data.php",
      "exec_at": "2022-10-31 09:45:06"
    }
  ]
}


PHP / Laravel / Yii2 Legacy Project Maintenance & Long-Term Technical Support

If your PHP / Laravel / Yii2 project is already in production but needs bug fixing, API troubleshooting, performance optimization, developer handover support, or long-term maintenance, feel free to contact me for remote technical support.

Ideal For:
✅ PHP legacy systems without active maintenance
✅ Laravel / Yii2 project bug fixes
✅ Admin panel feature iterations
✅ RESTful API troubleshooting
✅ MySQL / Redis / Nginx performance issues
✅ Long-term remote part-time maintenance

We can start with a small task:
✅ Production error troubleshooting
✅ API issue analysis
✅ Slow query and performance bottleneck diagnosis
✅ Initial code structure review
✅ Deployment environment and log inspection

If you would like to discuss your project, please contact me and mention: PHP Maintenance Consultation.

Contact Me:
Telegram: @shuijingwan
WeChat: 13980074657
Email: shuijingwanwq@gmail.com

评论

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.