© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
FilamentF
Filament•3y ago•
5 replies
Benjámin

Saving relationships when creating record with Repeater

I have an already working application with Filament v2, Laravel 9, PHP 8.0.
There's a Model called Menu. A Menu could be available on a given week, so when you create a Menu you have to assign Offers to it, and also Meals to the Offers, which is set on the Dish Model with the price and an active toggle.
So that's
Menu hasMany Offer
Menu hasMany Offer
,
Offer hasMany Dish
Offer hasMany Dish
,
Dish belongsToMany Meal
Dish belongsToMany Meal
.
This was already working well with 7 weekdays, but now there's a request to make it work with any amount of days, even like only weekends.

Let me show you the essential parts of the code.

Forms\Components\Repeater::make('offers')
  ->relationship('offers')
  ->defaultItems(7)
  ->minItems(7)
  ->maxItems(7)
  ->disableItemCreation()
  ->disableItemDeletion()
  ->schema([
    Forms\Components\Toggle::make('active')
      ...,
    Forms\Components\TextInput::make('price')
      ->integer()
      ...,
    Forms\Components\Grid::make(1)
      ->relationship('dish')
      ->schema([
          Forms\Components\Select::make('meal_id')
            ->multiple()
            // ->required() Not anymore
            ->options(Meal::all()->pluck('nameWithPrice', 'id')),
     ])
  ])
Forms\Components\Repeater::make('offers')
  ->relationship('offers')
  ->defaultItems(7)
  ->minItems(7)
  ->maxItems(7)
  ->disableItemCreation()
  ->disableItemDeletion()
  ->schema([
    Forms\Components\Toggle::make('active')
      ...,
    Forms\Components\TextInput::make('price')
      ->integer()
      ...,
    Forms\Components\Grid::make(1)
      ->relationship('dish')
      ->schema([
          Forms\Components\Select::make('meal_id')
            ->multiple()
            // ->required() Not anymore
            ->options(Meal::all()->pluck('nameWithPrice', 'id')),
     ])
  ])


I know the
Repeater
Repeater
could be used like... Add an item, then choose which day, than add another if wanted, but we want to keep these 7 items fixed, it works better UX wise.
How can I tell the
Repeater
Repeater
somehow, that it should only save the
Offer
Offer
when that
meal_id
meal_id
on the
Grid::relationship('dish')
Grid::relationship('dish')
exists?
I tried to solve this with
->saveRelationshipsUsing()
->saveRelationshipsUsing()
, but no luck so far.
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

Saving relationships
FilamentFFilament / ❓┊help
11mo ago
repeater with one record
FilamentFFilament / ❓┊help
3y ago
Save record and repeater with all Relationships on add item click
FilamentFFilament / ❓┊help
2y ago
Custom message when saving/creating
FilamentFFilament / ❓┊help
3y ago