© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
FilamentF
Filament•13mo ago•
5 replies
ffffer.

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),
            ]);
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');
    }
    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:

   
        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),
            ]);
Jump to solution
Filament banner
FilamentJoin
A powerful open source UI framework for Laravel • Build and ship admin panels & apps fast with Livewire
20,307Members
Resources
Was this page helpful?

Similar Threads

Recent Announcements

Similar Threads

Pivot-Table with Morph-Relation?
FilamentFFilament / ❓┊help
12mo ago
Creating morphOne with a hasOne relation from a morphTo relation manager
FilamentFFilament / ❓┊help
10mo ago
Use Spatie Translations with Morph Relation
FilamentFFilament / ❓┊help
3y ago
Sortable by morph-relation
FilamentFFilament / ❓┊help
3y ago