/** * Save the result to the database, or update any existing data. * * @return void */ protected function saveResult($result = null) { if (!is_null($result) && is_numeric($result)) { $start = $this->period->start; $end = $this->period->end; $stat = Stat::firstOrNew(['start' => $start, 'name' => $this->getStatName(), 'period' => $this->getPeriodName()]); $stat->value = $result; $stat->save(); } }