File tree Expand file tree Collapse file tree
Http/Controllers/Internal/v1 Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11{
22 "name" : " fleetbase/core-api" ,
3- "version" : " 1.6.42 " ,
3+ "version" : " 1.6.43 " ,
44 "description" : " Core Framework and Resources for Fleetbase API" ,
55 "keywords" : [
66 " fleetbase" ,
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace Fleetbase \Events ;
4+
5+ use Fleetbase \Models \Company ;
6+ use Fleetbase \Models \User ;
7+ use Illuminate \Broadcasting \InteractsWithSockets ;
8+ use Illuminate \Foundation \Events \Dispatchable ;
9+ use Illuminate \Queue \SerializesModels ;
10+
11+ class UserCreatedNewCompany
12+ {
13+ use Dispatchable;
14+ use InteractsWithSockets;
15+ use SerializesModels;
16+
17+ public $ user ;
18+ public $ company ;
19+
20+ /**
21+ * Create a new event instance.
22+ *
23+ * @return void
24+ */
25+ public function __construct (User $ user , Company $ company )
26+ {
27+ $ this ->user = $ user ;
28+ $ this ->company = $ company ;
29+ }
30+ }
Original file line number Diff line number Diff line change 22
33namespace Fleetbase \Http \Controllers \Internal \v1 ;
44
5+ use Fleetbase \Events \UserCreatedNewCompany ;
56use Fleetbase \Exceptions \InvalidVerificationCodeException ;
67use Fleetbase \Http \Controllers \Controller ;
78use Fleetbase \Http \Requests \AdminRequest ;
@@ -799,7 +800,22 @@ public function createOrganization(Request $request)
799800
800801 try {
801802 $ company = Company::create ($ input );
802- $ company ->assignUser ($ user , 'Administrator ' );
803+
804+ // Set company owner
805+ $ company ->setOwner ($ user )->save ();
806+
807+ // Assign user to organization
808+ $ user ->assignCompany ($ company , 'Administrator ' );
809+ $ user ->assignSingleRole ('Administrator ' );
810+
811+ // Company onboarding is not necessary - set correct flags
812+ $ company ->update ([
813+ 'onboarding_completed_at ' => now (),
814+ 'onboarding_completed_by_uuid ' => $ user ->uuid ,
815+ ]);
816+
817+ // Fire event that user created a new organization
818+ event (new UserCreatedNewCompany ($ user , $ company ));
803819 } catch (\Throwable $ e ) {
804820 return response ()->error ($ e ->getMessage ());
805821 }
You can’t perform that action at this time.
0 commit comments