$input * * @throws AuthorizationException * @throws ValidationException */ public function create(User $user, array $input): Organization { Gate::forUser($user)->authorize('create', Jetstream::newTeamModel()); Validator::make($input, [ 'name' => ['required', 'string', 'max:255'], ])->validateWithBag('createTeam'); $organization = new Organization; $organization->name = $input['name']; $organization->personal_team = false; $organization->owner()->associate($user); $organization->save(); $organization->users()->attach( $user, [ 'role' => Role::Owner->value, ] ); $user->switchTeam($organization); // Note: The refresh is necessary for currently unknown reasons. Do not remove it. $organization = $organization->refresh(); AfterCreateOrganization::dispatch($organization); return $organization; } }