Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Utchin's avatar

Create account when user registers

Hi,

I want to simplify the process of a user creating a team, and as soon as they register it will create the team with the name from the sign up form.

I was going to an event listener on UserRegistration but not sure what code to put in there.

$test = Spark::call(
            TeamRepository::class . '@create',
            [$user, $data]
        );

This only creates the team, not the team_users too.

0 likes
1 reply
Braunson's avatar

If you check in the Spark code, it shows the above but also where it appends the user who registered as the owner to the team.

If you have access to the repo https://github.com/laravel/spark-aurelius/blob/23107d494edb3165fd80b27c04f83528e4537c53/src/Interactions/Settings/Teams/CreateTeam.php#L72-L84

If you do not.. this is the code. You can see on the Spark::interact(AddTeamMemberContract part it adds the user to the team ;-)

    public function handle($user, array $data)
    {
        event(new TeamCreated($team = Spark::interact(
            TeamRepository::class.'@create', [$user, $data]
        )));

        Spark::interact(AddTeamMemberContract::class, [
            $team, $user, 'owner'
        ]);
        
        event(new TeamOwnerAdded($team, $user);

        return $team;
    }

So I'm not sure why your looking to change the Spark registration process as it already creates the team and adds the user registered as the owner already on register?

Please or to participate in this conversation.