F
Filament2mo ago
Medo

Advanced Nested Relationship Form builder

I have EventStaff Model Thats HasOne EventStaffDetail using staffDetails() method
public function staffDetails(): HasOne
{
return $this->hasOne(EventStaffDetail::class)
->withDefault();
}
public function staffDetails(): HasOne
{
return $this->hasOne(EventStaffDetail::class)
->withDefault();
}
Inside EventStaffDetail Model I have positions() method thats morphToMany StaffPosition
public function positions()
{
return $this->morphToMany(StaffPosition::class, 'positionable')
->withPivot('staff_position_id')
->withTimestamps();
}
public function positions()
{
return $this->morphToMany(StaffPosition::class, 'positionable')
->withPivot('staff_position_id')
->withTimestamps();
}
So From EventStaffResource Iam able to point to staffDetails Relation by passing relationship method to section
Section::make()->schema([
Wizard::make()
->schema([
Wizard\Step::make(__('Information About you'))
->schema([
Section::make(__('Positions'))
->description(__('Which position(s) most interests you?'))
->schema([
Repeater::make('positions')
->relationship('positions')
->schema([
Select::make('staff_position_id')
->label('Position')
->options(StaffPosition::all()->pluck('title', 'id')->toArray())
->searchable()
->required(),
]),
])
->columnSpan(1),
])
])
->contained(false)
->skippable(),
])->relationship('staffDetails')
Section::make()->schema([
Wizard::make()
->schema([
Wizard\Step::make(__('Information About you'))
->schema([
Section::make(__('Positions'))
->description(__('Which position(s) most interests you?'))
->schema([
Repeater::make('positions')
->relationship('positions')
->schema([
Select::make('staff_position_id')
->label('Position')
->options(StaffPosition::all()->pluck('title', 'id')->toArray())
->searchable()
->required(),
]),
])
->columnSpan(1),
])
])
->contained(false)
->skippable(),
])->relationship('staffDetails')
No description
1 Reply
Medo
MedoOP2mo ago
The problem now that when i save the form i got this error so it's ignore morp relation and try to update main staff_positions table So what is wrong and suggestions? By Using Select or CheckboxList i was able to use it but what if i have pivot columns ? how can i append pivot data ?
Want results from more Discord servers?
Add your server