award = $award; $this->user = $user; } /** * Run the main handler for this award class to determine if * it should be awarded or not */ public function handle() { if($this->check()) { $this->addAward(); } } /** * Add the award to this user, if they don't already have it * @return bool|UserAward */ protected function addAward() { $w = [ 'user_id' => $this->user->id, 'award_id' => $this->award->id ]; $found = UserAward::where($w)->count('id'); if ($found > 0) { return true; } // Associate this award to the user now $award = new UserAward($w); $award->save(); return $award; } }