marcf
marcf
FFilament
Created by marcf on 6/1/2024 in #❓┊help
Nested Repeater
Is it possible to have nested repeaters but specify the relationship of the nested one to be on the parent model? I have three tables: evenement, film, and seance, along with their respective pivot tables and models. I'm following the documentation for integrating with a BelongsToMany relationship from the Filament PHP Repeater Documentation. Here is my code:
Repeater::make('evenementFilms')
->relationship()
->schema([
Select::make('film_id')
->label("Film")
->options(Film::pluck('titre', 'id'))
->searchable()
->live(),
Repeater::make('evenementSeances')
// ->model(Evenement::class)
->label("Séances liés à cet Événement.")
->relationship('evenementSeances')
->schema([
Select::make('seance_id')
->label("Séance")
->options(Seance::pluck('debut', 'id'))
->searchable()
->live(),
]),
]),
Repeater::make('evenementFilms')
->relationship()
->schema([
Select::make('film_id')
->label("Film")
->options(Film::pluck('titre', 'id'))
->searchable()
->live(),
Repeater::make('evenementSeances')
// ->model(Evenement::class)
->label("Séances liés à cet Événement.")
->relationship('evenementSeances')
->schema([
Select::make('seance_id')
->label("Séance")
->options(Seance::pluck('debut', 'id'))
->searchable()
->live(),
]),
]),
In this setup, the nested repeater evenementSeances defaults to the pivot model (EvenementFilm) instead of the parent model (Evenement). If I uncomment the model specification (->model(Evenement::class)), the relationship does not save correctly. My goal is for the user to first choose a film, and then, if they want, choose sessions for each selected film. How can I correctly specify the relationship for the nested repeater to be on the parent model? Regards
7 replies