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
toeknee7d ago
That's fine 🙂 What are you wanting to do to trigger the state change?
topan
topanOP7d ago
I want to create email_verify_at, when it is null then show not verify otherwise when it doesn't show verify
toeknee
toeknee7d ago
try: ->nullable()
topan
topanOP7d ago
no, not verify does not appear
toeknee
toeknee7d 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
topanOP7d ago
everything is verified
topan
topanOP7d ago
No description
toeknee
toeknee7d ago
Re-add your code just set the default My bad on how default works, it’s been a while 😄
topan
topanOP7d ago
okay, that's fine, thanks
atlas
atlas7d 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
toeknee6d 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.
Want results from more Discord servers?
Add your server