From 09bf3770bf30f5073e22533caca5fc816cdeb519 Mon Sep 17 00:00:00 2001 From: "Ronald A. Richardson" Date: Wed, 22 Apr 2026 15:56:36 +0800 Subject: [PATCH] Add an event for when user creates a new additional company --- composer.json | 2 +- src/Events/UserCreatedNewCompany.php | 30 +++++++++++++++++++ .../Internal/v1/AuthController.php | 18 ++++++++++- 3 files changed, 48 insertions(+), 2 deletions(-) create mode 100644 src/Events/UserCreatedNewCompany.php diff --git a/composer.json b/composer.json index e75bb402..42fe5bfa 100644 --- a/composer.json +++ b/composer.json @@ -1,6 +1,6 @@ { "name": "fleetbase/core-api", - "version": "1.6.42", + "version": "1.6.43", "description": "Core Framework and Resources for Fleetbase API", "keywords": [ "fleetbase", diff --git a/src/Events/UserCreatedNewCompany.php b/src/Events/UserCreatedNewCompany.php new file mode 100644 index 00000000..3a873bbc --- /dev/null +++ b/src/Events/UserCreatedNewCompany.php @@ -0,0 +1,30 @@ +user = $user; + $this->company = $company; + } +} diff --git a/src/Http/Controllers/Internal/v1/AuthController.php b/src/Http/Controllers/Internal/v1/AuthController.php index 70b4953e..ba9d8160 100644 --- a/src/Http/Controllers/Internal/v1/AuthController.php +++ b/src/Http/Controllers/Internal/v1/AuthController.php @@ -2,6 +2,7 @@ namespace Fleetbase\Http\Controllers\Internal\v1; +use Fleetbase\Events\UserCreatedNewCompany; use Fleetbase\Exceptions\InvalidVerificationCodeException; use Fleetbase\Http\Controllers\Controller; use Fleetbase\Http\Requests\AdminRequest; @@ -799,7 +800,22 @@ public function createOrganization(Request $request) try { $company = Company::create($input); - $company->assignUser($user, 'Administrator'); + + // Set company owner + $company->setOwner($user)->save(); + + // Assign user to organization + $user->assignCompany($company, 'Administrator'); + $user->assignSingleRole('Administrator'); + + // Company onboarding is not necessary - set correct flags + $company->update([ + 'onboarding_completed_at' => now(), + 'onboarding_completed_by_uuid' => $user->uuid, + ]); + + // Fire event that user created a new organization + event(new UserCreatedNewCompany($user, $company)); } catch (\Throwable $e) { return response()->error($e->getMessage()); }