RelationManager with relation having a morph
Ti, I have a RelationManager, and that model is related with a morphOne:
class RoundRelationManager extends RelationManager
{
protected static string $relationship = 'rounds';
public function form(Form $form): Form
{
return $form
->schema([
Forms\Components\Section::make('earlySale')
->label('Early Sale')
->schema([
Forms\Components\DateTimePicker::make('earlySale.start_at')
->label('Early sale Start')
->requiredWith('start_at')
->reactive()
//->formatStateUsing(fn($record) => $record->earlySale?->created_at?->format('Y-m-d H:i:s')),
,
Forms\Components\DateTimePicker::make('earlySale.finish_at')
->label('Early sale Finish')
->requiredWith('finish_at')
->reactive()
//->formatStateUsing(fn($record) => $record->earlySale?->finish_at?->format('Y-m-d H:i:s')),
])
->columns(2),
]);
In the model:
public function earlySale()
{
return $this->morphOne(EarlySale::class, 'saleable');
}
The problem is that without the formatStateUsing, the data is not loaded, and the problem is that (with and without formatStateUsing), the new values are not stored.
Ideas please?
thanksSolution:Jump to solution
That looks to be because you are using dot notations in forms. I think you want:
```php
return $form...
return $form...
3 Replies
The question is, it's not filament native use in a RelationManager a relation with another model that uses morph?
Solution
That looks to be because you are using dot notations in forms. I think you want:
That works, the problem is that I didn't know I can apply relationship at Section level. Thanks