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? thanks
Solution:
That looks to be because you are using dot notations in forms. I think you want: ```php
return $form...
Jump to solution
3 Replies
ffffer.
ffffer.OP3w ago
The question is, it's not filament native use in a RelationManager a relation with another model that uses morph?
Solution
toeknee
toeknee3w ago
That looks to be because you are using dot notations in forms. I think you want:

return $form
->schema([
Forms\Components\Section::make('earlySale')
->relationship('earlySale')
->label('Early Sale')
->schema([
Forms\Components\DateTimePicker::make('start_at')
->label('Early sale Start')
->requiredWith('start_at')
->live()
->displayFormat('Y-m-d H:i:s'),
Forms\Components\DateTimePicker::make('finish_at')
->label('Early sale Finish')
->requiredWith('finish_at')
->live()
->displayFormat('Y-m-d H:i:s')
])
->columns(2),
]);

return $form
->schema([
Forms\Components\Section::make('earlySale')
->relationship('earlySale')
->label('Early Sale')
->schema([
Forms\Components\DateTimePicker::make('start_at')
->label('Early sale Start')
->requiredWith('start_at')
->live()
->displayFormat('Y-m-d H:i:s'),
Forms\Components\DateTimePicker::make('finish_at')
->label('Early sale Finish')
->requiredWith('finish_at')
->live()
->displayFormat('Y-m-d H:i:s')
])
->columns(2),
]);
ffffer.
ffffer.OP2w ago
That works, the problem is that I didn't know I can apply relationship at Section level. Thanks

Did you find this page helpful?