Doesn’t work with model accessors
RicLeP opened this issue · comments
Ric Le Poidevin commented
I’ve a table with a renewal date field (timestamp) and what to show a status. If the renewal date field has expired then I want to display fact. Here’s my code - but it just shows a dash and no label on the index view.
// Model
public function membershipStatusAttribute() {
if ($this->renewal_date < now()) {
return 'expired';
} else {
return 'valid';
}
}
// Nova resource
Indicator::make('membership_status')
->labels([
'expired' => 'Expired',
'valid' => 'Valid',
])->colors([
'expired' => 'red',
'valid' => 'green',
]),
Kit Burton-Senior commented
The syntax for Eloquent model accessors is "get...Attribute", so your first example needs to be getMembershipStatusAttribute, not membershipStatusAttribute. The resource syntax is correct.