© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
FilamentF
Filament•3y ago•
4 replies
@nasilemak

Upload multiple images to a model

I have a
Project
Project
model and I want the user to be able to upload many images for each project.

I'm storing the images in an
images
images
table.

class Project extends Model
{
    protected $casts = [
        'images' => 'array',
    ];

    public function images(): MorphMany
    {
        return $this->morphMany(Image::class, 'imageable');
    }
}
class Project extends Model
{
    protected $casts = [
        'images' => 'array',
    ];

    public function images(): MorphMany
    {
        return $this->morphMany(Image::class, 'imageable');
    }
}


Schema::create('images', function (Blueprint $table) {
    $table->id();
    $table->string('url');
    $table->unsignedBigInteger('imageable_id');
    $table->string('imageable_type');
    $table->timestamps();
});
Schema::create('images', function (Blueprint $table) {
    $table->id();
    $table->string('url');
    $table->unsignedBigInteger('imageable_id');
    $table->string('imageable_type');
    $table->timestamps();
});


How do I allow the user to upload images and have them associated to the
Project
Project
model being created?

FileUpload::make('images')
    ->image()
    ->multiple()
    ->maxFiles(10)
    ->reorderable(),
FileUpload::make('images')
    ->image()
    ->multiple()
    ->maxFiles(10)
    ->reorderable(),
Solution
If you use multiple() Filament expects the file paths to be saved in a json array on the model. If you want to use a morph relationship, you will want to use a relation manager or write some custom logic that will use the array, create and attach the related models, unset the data on the original model, etc.
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
Was this page helpful?

Similar Threads

Recent Announcements

Similar Threads

How to add multiple images to a model
FilamentFFilament / ❓┊help
3y ago
Multiple images upload issue on mobile
FilamentFFilament / ❓┊help
11mo ago
Gallery with Multiple Images and multiple image upload
FilamentFFilament / ❓┊help
3y ago
Unable to upload multiple images at the same time
FilamentFFilament / ❓┊help
2y ago