0, 'counter' => 1, ]; /** * The attributes that should be casted to native types. * * @var string[] */ protected $casts = [ 'metric_id' => 'int', 'value' => 'float', 'counter' => 'int', ]; /** * The attributes that are mass assignable. * * @var string[] */ protected $fillable = [ 'metric_id', 'value', 'counter', 'created_at', ]; /** * The validation rules. * * @var string[] */ public $rules = [ 'value' => 'required|numeric', ]; /** * Get the metric relation. * * @return \Illuminate\Database\Eloquent\Relations\BelongsTo */ public function metric() { return $this->belongsTo(Metric::class); } /** * Override the value attribute. * * @param mixed $value * * @return float */ public function getActiveValueAttribute($value) { if ($this->metric->calc_type === Metric::CALC_SUM) { return round((float) $value * $this->counter, $this->metric->places); } return round((float) $value, $this->metric->places); } /** * Get the presenter class. * * @return string */ public function getPresenterClass() { return MetricPointPresenter::class; } }