How to manage n-n relationship in this case ?

Hello, I'm having a bit of trouble figuring out how to handle the data registration in the intermediate table in this relationship. I save the framework ID in the 'sheets' table, but once the framework is determined, another select appears and allows choosing skills from this selected framework in the previous select. I was thinking of attaching each skill in the afterCreate() function, but when the resource is edited, it becomes more complicated ...

Part of the Form with selects :
Select::make('framework_id')
    ->label('Référentiel')
    ->relationship('sheetFramework', 'title')
    ->native(false)
    ->live()
    ->afterStateUpdated(fn (Forms\Set $set) => $set('framework_competencies', null)),
Select::make('framework_competencies')
    ->label('Compétences')
    ->options(function (Builder $query, Forms\Get $get) {
        return Competency::where('competency_framework_id', $get('framework_id'))->pluck('title', 'id')->toArray();
    })
    ->multiple()
    ->live()
    ->hidden(fn (Forms\Get $get) => blank($get('framework_id')))


Help would be really appreciated 🙂
image.png
image.png
Was this page helpful?