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

kerrin's avatar

Create Team automatically on User Registration

I am using Teams in Spark but without Team Billing. A user can create as many teams as they want - but it is an optional thing and not required when they first start using the app.

What I would like to be able to configure is that when a user first registers, a Team is created but just with the same name as the user and that this particular team will only ever have a maximum of one user.

That way I can keep all logic throughout the app based on Teams.

What's the best way to approach adding the team creation to the registration process without making future upgrades more difficult then necessary?

Thanks :)

0 likes
3 replies
bugsysha's avatar

Either use events or observers.

Events:

// app/User.php
protected $dispatches = [
    'created' => UserCreatedEvent::class,
];

// app/Providers/EventServiceProvider.php
protected $listen = [
    UserCreatedEvent::class => CreateTeamListener::class,
];

// app/Listeners/CreateTeamListener.php
// in handle method just create new team for that user and that is it

Observers:

// let me know if you do not want to use events

I love events more since they have specific reusable chunks, while observers can get messy and huge.

1 like
kerrin's avatar

Thanks @bugsysha, I'll have a play and let you know how I get on. Cheers Kerrin

kerrin's avatar

After a bit of playing around, I found the Spark event (UserRegistered) and have now hooked in to that. Seems to be working well.

/**
 * Handle the event.
 *
 * @param  UserRegistered  $event
 * @return void
 */
public function handle(UserRegistered $event)
{
    Spark::interact(CreateTeam::class, [
        $event->user, ['name' => 'Solo', 'slug' => 'Solo']
    ]);

    $event->user->currentTeam();
}

Thanks for your help.

Please or to participate in this conversation.