request = $request; } /** * Execute the job. * * @return void */ public function handle() : ?User { /* * Create account */ $account = Account::create($this->request); /* * Create company */ $company = CreateCompany::dispatchNow($this->request, $account); /* * Set default company */ $account->default_company_id = $company->id; $account->save(); /* * Create user */ $user = CreateUser::dispatchNow($this->request, $account, $company); /* * Set current company */ $this->setCurrentCompanyId($user->companies()->first()->account->default_company_id); /* * Login user */ Auth::loginUsingId($user->id, true); /* * Fire related events */ event(new AccountCreated($user)); return $user; } }