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 */ $user_agent = isset($this->request['token_name']) ? $this->request['token_name'] : request()->server('HTTP_USER_AGENT'); $company_token = CreateCompanyToken::dispatchNow($company, $user, $user_agent); /* * Fire related events */ if ($user) { event(new AccountCreated($user)); } $user->fresh(); Notification::route('slack', config('ninja.notification.slack')) ->notify(new NewAccountCreated($user, $company)); return $account; } }