© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
FilamentF
Filament•3y ago•
2 replies
gepesivan

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([
         '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'],
                     ...
    ]);
}
Jump to solution
Filament banner
FilamentJoin
A powerful open source UI framework for Laravel • Build and ship admin panels & apps fast with Livewire
20,307Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

Error when importing
FilamentFFilament / ❓┊help
2y ago
Is there any way to delete old image/attachments when deleting or updating records??
FilamentFFilament / ❓┊help
3y ago
Keep the records selected when filtering
FilamentFFilament / ❓┊help
5mo ago