© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
FilamentF
Filament•3y ago•
7 replies
Mdk

Filling a SpatieMediaLibraryImageEntry field programmatically on a new Model (not saved yet)

I'm trying to set up a "cloning" functionality where the user can pick an existing Item and make a copy that he can edit before saving it as his own
I made a copy of the
CreateRecord
CreateRecord
page that accept an extra param (the ID of the item to be cloned) and added this
protected function afterFill(): void
{
  $item = Item::findOrFail($this->item);
  $this->data['status'] = 'enabled';
  $this->data['title'] = $item->title;
  $this->data['description'] = $item->description;
}
protected function afterFill(): void
{
  $item = Item::findOrFail($this->item);
  $this->data['status'] = 'enabled';
  $this->data['title'] = $item->title;
  $this->data['description'] = $item->description;
}


So far so good, but my Items also have images attached, via the SpatieMediaLibrary plugin, and I can't find a way to bring the original item's images in the form

I thought about persisting the item to the database and then using the
EditRecord
EditRecord
page but that would be extra clutter in case the user doesn't actually save his item anymore

Any other way to auto-fill that field from existing images (that would then have to be copied over to new Model as well)?
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

Relationship not saved to Model on Section
FilamentFFilament / ❓┊help
3y ago
SpatieMediaLibraryImageEntry
FilamentFFilament / ❓┊help
3y ago
Stop New Password field auto-filling
FilamentFFilament / ❓┊help
3y ago