Updating existing records when importing

My record has a foreig key to an other table, this is a BelongsTo relationship in the model. Is it possibe to use this relationship in the models' firstOrNew function when looking up the record in the importer's resolveRecord()?
Solution:
This is how i solved it: ```
public function resolveRecord(): ?Product { return Product::firstOrNew([...
Jump to solution
1 Reply
Solution
gepesivan
gepesivan11mo ago
This is how i solved it:

public function resolveRecord(): ?Product
{
return Product::firstOrNew([
'othet_model_id_id' => OtherModel::where('short_name', $this->data['other_model'])->first()?->id,
'name' => $this->data['name'],
...
]);
}

public function resolveRecord(): ?Product
{
return Product::firstOrNew([
'othet_model_id_id' => OtherModel::where('short_name', $this->data['other_model'])->first()?->id,
'name' => $this->data['name'],
...
]);
}
Want results from more Discord servers?
Add your server