F
Filament4mo ago
Geo

How to ignore the mutator and get the original value of a property?

I have a user model that has a getEmailAttribute that perform mutations to the user emails, how can display and modify the original email attribute that is saved in the database and basically ignore the mutator. Same as what getRawOriginal do. this is what i have on my model:
public function getEmailAttribute()
{
if (is_null($this->identified_at)) {
return null;
}

if($this->attributes['email']) {
return $this->attributes['email'];
}
}
public function getEmailAttribute()
{
if (is_null($this->identified_at)) {
return null;
}

if($this->attributes['email']) {
return $this->attributes['email'];
}
}
and this is what i have on the UserResource table Tables\Columns\TextColumn::make('email')->searchable(), but it is not displayed since identified_at is null thanks in advance
Solution:
okay solved it for the edit 🥳 ```php ->formatStateUsing(function (Model $record): string { return $record->getRawOriginal('email'); })...
Jump to solution
2 Replies
Geo
Geo4mo ago
One way to solve it is using
->getStateUsing(fn ($record) => $record->getRawOriginal('email'))
->getStateUsing(fn ($record) => $record->getRawOriginal('email'))
is this the only way ? the above worked only on tables but not of forms or view on view the following worked
Infolists\Components\TextEntry::make('email')
->state(function (Model $record): string {
return $record->getRawOriginal('email');
}),
Infolists\Components\TextEntry::make('email')
->state(function (Model $record): string {
return $record->getRawOriginal('email');
}),
Still struggling with the edit form
Solution
Geo
Geo4mo ago
okay solved it for the edit 🥳
->formatStateUsing(function (Model $record): string {
return $record->getRawOriginal('email');
})
->formatStateUsing(function (Model $record): string {
return $record->getRawOriginal('email');
})
Want results from more Discord servers?
Add your server
More Posts