F
Filament3mo ago
topan

Change State

how to use state correctly? i am a beginner
TextColumn::make('email_verified_at')
->label('Status Email')
->badge()
->color(function (string $state) {
return !$state ? "danger" : "success";
})
->sortable()
->formatStateUsing(function (string $state): string {
return (string)!$state ? "Not Verified" : "Verified";
}),
TextColumn::make('email_verified_at')
->label('Status Email')
->badge()
->color(function (string $state) {
return !$state ? "danger" : "success";
})
->sortable()
->formatStateUsing(function (string $state): string {
return (string)!$state ? "Not Verified" : "Verified";
}),
No description
11 Replies
toeknee
toeknee3mo ago
That's fine 🙂 What are you wanting to do to trigger the state change?
topan
topanOP3mo ago
I want to create email_verify_at, when it is null then show not verify otherwise when it doesn't show verify
toeknee
toeknee3mo ago
try: ->nullable()
topan
topanOP3mo ago
no, not verify does not appear
toeknee
toeknee3mo ago
Ignore that one, actually we introduced default so:
->default('Not Verified')
->formatStateUsing(function (string $state): string {
return "Verified";
}),
->default('Not Verified')
->formatStateUsing(function (string $state): string {
return "Verified";
}),
Should work
topan
topanOP3mo ago
everything is verified
topan
topanOP3mo ago
No description
toeknee
toeknee3mo ago
Re-add your code just set the default My bad on how default works, it’s been a while 😄
topan
topanOP3mo ago
okay, that's fine, thanks
atlas
atlas3mo ago
->badge()
->getStateUsing(fn ($record) => $record->email_verified_at ? 'Verified' : 'Not Verified')
->color(fn ($state) => $state === 'Verified' ? 'success' : 'danger'),
->badge()
->getStateUsing(fn ($record) => $record->email_verified_at ? 'Verified' : 'Not Verified')
->color(fn ($state) => $state === 'Verified' ? 'success' : 'danger'),
toeknee
toeknee3mo ago
I wouldn’t usually use getStateUsing it adds un-needed overhead in this situation since the state is already there and works. You’re now processing an entire record opposed to the state.

Did you find this page helpful?