F
Filamentβ€’17mo ago
Tritus

Repeater and pivot table

Hi, I'm facing an issue with Repeater and a BelongsToMany Relationship. Here's my Project model :
class Project extends Model
{
public function members(): BelongsToMany
{
return $this->belongsToMany(User::class);
}
}
class Project extends Model
{
public function members(): BelongsToMany
{
return $this->belongsToMany(User::class);
}
}
My pivot table, called "project_user", has a "project_role" column. Then I have in my EditProject (App\Filament\Resources\ProjectResource\Pages\EditProject) the following Repeater :
Repeater::make('members')->schema([

Select::make('user_id')->label('Member email')->options(User::all()->pluck('email', 'id'))->searchable()->required(),

Select::make('project_role')->options(...)->required()
])->createItemButtonLabel('Add member')
Repeater::make('members')->schema([

Select::make('user_id')->label('Member email')->options(User::all()->pluck('email', 'id'))->searchable()->required(),

Select::make('project_role')->options(...)->required()
])->createItemButtonLabel('Add member')
I'd like the "project_role" select to automatically fill this pivot column, however it does not work, it tries to fill my "users" table. Any idea?
3 Replies
Tritus
TritusOPβ€’17mo ago
The only solution I found was to create a hasMany relationship with the pivot table explicitly in the Project Model
Patrick Boivin
Patrick Boivinβ€’17mo ago
Yes, that's it. The question comes up regularly in the chat.
Tritus
TritusOPβ€’17mo ago
Thanks πŸ™‚
Want results from more Discord servers?
Add your server