Skip to content

Instantly share code, notes, and snippets.

@inxilpro
Created February 23, 2022 20:55
Show Gist options
  • Save inxilpro/c4650bf3ecf739b0a5fba1243e0f9b5a to your computer and use it in GitHub Desktop.
Save inxilpro/c4650bf3ecf739b0a5fba1243e0f9b5a to your computer and use it in GitHub Desktop.
File 1:
REMOVE: LegacyRecord::each(function($record) {
ADD: LegacyRecord::with('new_record')->each(function($record) {
$identity = ['legacy_id' => $record->id];
$values = $this->transformLegacyRecord($record);
REMOVE: NewRecord::updateOrCreate($identity, $values);
ADD: $new_record = $record->new_record ?? NewRecord::make($identity);
ADD: $new_record->fill($this->transformLegacyRecord($record));
ADD: $new_record->save();
});
File 2:
class LegacyRecord extends Model
{
ADD: public function new_record()
ADD: {
ADD: return $this->hasOne(NewRecord::class, 'legacy_id');
ADD: }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment