inspheric / nova-indicator-field

A colour-coded indicator field for Laravel Nova

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Doesn’t work with model accessors

RicLeP opened this issue · comments

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',
	]),

The syntax for Eloquent model accessors is "get...Attribute", so your first example needs to be getMembershipStatusAttribute, not membershipStatusAttribute. The resource syntax is correct.