user = $user->fresh(); $this->last = $last; } public function handle() { $time = [now()->startOfMonth()->toDateTimeString(), now()->endOfMonth()->toDateTimeString()]; if ($this->last) { $time = [ now()->subMonth()->startOfMonth()->toDateTimeString(), now()->subMonth()->endOfMonth()->toDateTimeString() ]; } $old = $this->user->allPerf(); $new = $this->user->allPerf($time); BounsUserPerf::updateOrCreate([ 'user_id' => $this->user->id, 'date' => $time[0], ], [ 'star' => $this->user->identityFirst()->pivot->star, 'old_perf' => $old, 'new_perf' => $new, ]); } }