['value' => 'daily', 'label' => 'daily'], ]; /** * @inheritdoc */ protected $fillable = [ 'frequency', 'from', 'goal', 'name', 'to', ]; /** * @inheritdoc */ protected $casts = [ 'from' => 'datetime:Y-m-d', 'goal' => 'float', 'to' => 'datetime:Y-m-d', ]; /** * @inheritdoc */ protected $appends = [ 'summary', ]; /** * Get the User this goal belongs to. */ public function user(): BelongsTo { return $this->belongsTo(User::class); } public function getSummaryAttribute(): string { $nameOptions = self::getNameOptions(); return number_format($this->goal) . "{$nameOptions[$this->name]['unit']} {$nameOptions[$this->name]['label']} {$this->frequency}"; } /** * Get options for the "name" column. */ public static function getNameOptions(): array { $options = []; foreach (Nutrients::all() as $nutrient) { $options[$nutrient['value']] = [ 'value' => $nutrient['value'], 'label' => $nutrient['label'], 'unit' => $nutrient['unit'], ]; } return $options; } }