marcf
marcf
FFilament
Created by marcf on 6/1/2024 in #❓┊help
Nested Repeater
Thanks
7 replies
FFilament
Created by marcf on 6/1/2024 in #❓┊help
Nested Repeater
7 replies
FFilament
Created by marcf on 6/1/2024 in #❓┊help
Nested Repeater
After triple checking my code, my db and my model, I think this is a Filament bug. I manage to do a work around with this code (using saveRelationshipsUsing) but I need to implement again update, delete, create.
Repeater::make('evenementFilms')
->relationship()
->schema([
Select::make('film_id')
->label("Film")
->options(Film::pluck('titre', 'id'))

->searchable()
->live(),
Repeater::make('evenementFilmSeances')
->label("Séance liés à cette Événement.")
->relationship()
->schema([
Select::make('seance_id')
->relationship('seance', 'debut')
->options(function ($get) {
return Seance::where('film_id', $get('../../film_id'))->pluck('debut', 'id');
})
])
->saveRelationshipsUsing(function ($state, $record) {
if (!isset($record['id'])) {
$filmId = $record['film_id'];
$evenementId = $record["evenement_id"];
$evFilm = $record->where('film_id', $filmId)->where('evenement_id', $evenementId)->first();
} else {
$evFilm = $record;
}
$evFilm->load('evenementFilmSeances');

// Here code to update, create, delete
Repeater::make('evenementFilms')
->relationship()
->schema([
Select::make('film_id')
->label("Film")
->options(Film::pluck('titre', 'id'))

->searchable()
->live(),
Repeater::make('evenementFilmSeances')
->label("Séance liés à cette Événement.")
->relationship()
->schema([
Select::make('seance_id')
->relationship('seance', 'debut')
->options(function ($get) {
return Seance::where('film_id', $get('../../film_id'))->pluck('debut', 'id');
})
])
->saveRelationshipsUsing(function ($state, $record) {
if (!isset($record['id'])) {
$filmId = $record['film_id'];
$evenementId = $record["evenement_id"];
$evFilm = $record->where('film_id', $filmId)->where('evenement_id', $evenementId)->first();
} else {
$evFilm = $record;
}
$evFilm->load('evenementFilmSeances');

// Here code to update, create, delete
Sorry for this big message. Do you think I post an issue on filament github ?
7 replies
FFilament
Created by marcf on 6/1/2024 in #❓┊help
Nested Repeater
My pivot model are :
```php
class EvenementFilm extends Pivot
{
public function film(): BelongsTo
{
return $this->belongsTo(Film::class, 'film_id', 'id');
}

public function evenement(): BelongsTo
{
return $this->belongsTo(Evenement::class, 'evenement_id', 'id');
}

public function evenementFilmSeances(): HasMany
{
return $this->hasMany(EvenementFilmSeance::class, 'evenement_film_id', 'id');
}
}

class EvenementFilmSeance extends Pivot
{
public function evenementFilm(): BelongsTo
{
return $this->belongsTo(EvenementFilm::class, 'evenement_film_id');
}
public function seance(): BelongsTo
{
return $this->belongsTo(Seance::class, 'seance_id');
}
}
```php
class EvenementFilm extends Pivot
{
public function film(): BelongsTo
{
return $this->belongsTo(Film::class, 'film_id', 'id');
}

public function evenement(): BelongsTo
{
return $this->belongsTo(Evenement::class, 'evenement_id', 'id');
}

public function evenementFilmSeances(): HasMany
{
return $this->hasMany(EvenementFilmSeance::class, 'evenement_film_id', 'id');
}
}

class EvenementFilmSeance extends Pivot
{
public function evenementFilm(): BelongsTo
{
return $this->belongsTo(EvenementFilm::class, 'evenement_film_id');
}
public function seance(): BelongsTo
{
return $this->belongsTo(Seance::class, 'seance_id');
}
}
7 replies
FFilament
Created by marcf on 6/1/2024 in #❓┊help
Nested Repeater
Hi everyone, I've made changes to my database schema. Now, I've introduced events to which I'm attaching films, and I'm indicating that certain screenings of these films are also event screenings. For this purpose, I now have a table for films, seance, evenement, as well as two pivot tables, evenement_film and evenement_film_seance.
Schema::create('evenement_film', function (Blueprint $table) {
$table->id();
$table->foreignId('evenement_id')->constrained()->onDelete('cascade');
$table->foreignId('film_id')->constrained()->onDelete('cascade');
});

Schema::create('evenement_film_seance', function (Blueprint $table) {
$table->id();
$table->foreignId('seance_id')->constrained()->onDelete('cascade');
$table->foreignId('evenement_film_id')->nullable()->constrained('evenement_film')->onDelete('cascade');
});
Schema::create('evenement_film', function (Blueprint $table) {
$table->id();
$table->foreignId('evenement_id')->constrained()->onDelete('cascade');
$table->foreignId('film_id')->constrained()->onDelete('cascade');
});

Schema::create('evenement_film_seance', function (Blueprint $table) {
$table->id();
$table->foreignId('seance_id')->constrained()->onDelete('cascade');
$table->foreignId('evenement_film_id')->nullable()->constrained('evenement_film')->onDelete('cascade');
});
I've also created pivot models EvenementFilm and EvenementFilmSeance following the tutorial "Integrating with a BelongsToMany Eloquent Relationship". My resource is now configured as follows:
Repeater::make('evenementFilms')
->relationship()
->schema([
Select::make('film_id')
->label("Film")
->options(Film::pluck('titre', 'id'))
->searchable()
->live(),
Repeater::make('evenementFilmSeances')
->label("Screenings linked to this Event.")
->relationship()
->schema([
Select::make('seance_id')
->label("Screening")
->options(function ($get) {
return Seance::where('film_id', $get('../../film_id'))->pluck('debut', 'id');
})
])
])
Repeater::make('evenementFilms')
->relationship()
->schema([
Select::make('film_id')
->label("Film")
->options(Film::pluck('titre', 'id'))
->searchable()
->live(),
Repeater::make('evenementFilmSeances')
->label("Screenings linked to this Event.")
->relationship()
->schema([
Select::make('seance_id')
->label("Screening")
->options(function ($get) {
return Seance::where('film_id', $get('../../film_id'))->pluck('debut', 'id');
})
])
])
I'm facing another issue: during the first save, the evenement_film_id column in the evenement_film_seance table is null. If I save it again, it adds a new entry with all the information.
7 replies