FilamentF
Filament16mo ago
Garrita

Save Spatie Media Library File in Relationship

I have a form resource where I save the child and the parent but when I try to save the files for the parent it does not store them, just the other attributes except the files.

Models: AuctionCar belongsTo Car

AuctionCarResource.php
In this case, I save the mileage and the license plate for the parent, but it does not save the images.

Group::make()
  ->relationship('car')
  ->schema([
      TextInput::make('mileage')
          ->label(__('Mileage'))
          ->numeric()
          ->suffix(__('km.'))
          ->required(),

      TextInput::make('license_plate')
          ->label(__('License Plate'))
          ->unique('cars', 'license_plate', ignoreRecord: true)
          ->live()
          ->afterStateUpdated(function (HasForms $livewire, TextInput $component) {
              $livewire->validateOnly($component->getStatePath());
          })
          ->required(),

      SpatieMediaLibraryFileUpload::make('images')
          ->label(__('Images'))
          ->multiple()
          ->image()
          ->required(),
  ])
  ->columns(3)`
  ->columnSpan(3),
Was this page helpful?