/** * Execute the job. * * @param Code $code * @return bool */ public function handle(Code $code) { /** @var Code $result */ $result = $code->whereCode($this->code)->firstOrFail(); /** * Check if already there is an user associated with this code */ if ($result->user) { return false; } $result->setAttribute('status', true); $result->user()->associate($this->user); $result->save(); return true; }