© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
FilamentF
Filament•2y ago
Florian Langer

MorphOne mutateRelationshipDataBeforeCreateUsing does not work properly

For some reason, if I use
mutateRelationshipDataBeforeCreateUsing()
mutateRelationshipDataBeforeCreateUsing()
the related model gets created with the correct values used in the closure, but Filament runs an update query right after the creation, with the original data inputted. I can also confirm this by using
mutateRelationshipDataBeforeSaveUsing(),
mutateRelationshipDataBeforeSaveUsing(),
because this runs as well and does not have the mutated data from
mutateRelationshipDataBeforeCreateUsing()
mutateRelationshipDataBeforeCreateUsing()
.

I'm confused, why Filament does behave like this.

It's a problem, because I cannot set my token without getting SQL exceptions, when Filament tries to update it immediately after creation with the wrong value.

Code:
                Forms\Components\Section::make()
                    ->relationship('qrToken')
                    ->schema([
                        Forms\Components\TextInput::make('token'),
                    ])
                    ->mutateRelationshipDataBeforeCreateUsing(function (array $data) {
                        $data['token'] = QRCodeService::generateQRCodeToken();

                        return $data;
                    })
                    ->mutateRelationshipDataBeforeSaveUsing(function (array $data) {
                        dd($data); // --> Outputs the value inputted by the user NOT the mutated one.
                    return $data;
                }),
                Forms\Components\Section::make()
                    ->relationship('qrToken')
                    ->schema([
                        Forms\Components\TextInput::make('token'),
                    ])
                    ->mutateRelationshipDataBeforeCreateUsing(function (array $data) {
                        $data['token'] = QRCodeService::generateQRCodeToken();

                        return $data;
                    })
                    ->mutateRelationshipDataBeforeSaveUsing(function (array $data) {
                        dd($data); // --> Outputs the value inputted by the user NOT the mutated one.
                    return $data;
                }),
Filament banner
FilamentJoin
A powerful open source UI framework for Laravel • Build and ship admin panels & apps fast with Livewire
20,307Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

RichEdit grid not work properly
FilamentFFilament / ❓┊help
5mo ago
MorphOne in Forms is not working
FilamentFFilament / ❓┊help
3y ago
Validation does not work
FilamentFFilament / ❓┊help
3y ago
use morphOne with select
FilamentFFilament / ❓┊help
2y ago