public function update($data) { $score = null; if (isset($data['id'])) { if ($score = Score::find($data['id'])) { $score->update($data); } } return $score; }
/** * Bootstrap any application services.customers * * @return void */ public function boot() { History::creating(function ($history) { $score = Score::find($history->product_id); if (!is_null($score)) { $score->score++; $score->number_command += $history->quantity; $score->save(); } else { Score::create(['score' => 1, 'number_command' => $history->quantity]); } }); }