request = $request; } /** * Execute the job. * * @return void */ public function handle() : ?Account { /* * Create account */ $account = Account::create($this->request); /* * Create company */ $company = CreateCompany::dispatchNow($this->request, $account); $company->load('account'); /* * Set default company */ $account->default_company_id = $company->id; $account->save(); /* * Create user */ $user = CreateUser::dispatchNow($this->request, $account, $company, true); //make user company_owner /* * Required dependencies */ if($user) auth()->login($user, false); $user->setCompany($company); /* * Create token */ $company_token = CreateCompanyToken::dispatchNow($company, $user); /* * Login user */ //Auth::loginUsingId($user->id, true); /* * Fire related events */ if($user) event(new AccountCreated($user)); return $account; } }