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

obs's avatar
Level 3

Create a User and Team programmatically

I want to use the API to create a user programmatically. Since I use teams, I need to create a team as well and activate a billing plan. How can I do this? I couldn't find any documentation on this.

I found this info about seeding: https://gist.github.com/dillinghamio/fd32bd49b0176a085dc088f3bd2d01c7

So what I have so far is this:

$user = User::create([
    'name' => $data['name'],
    'email' => $data['email'],
    'password' => Hash::make($data['password']),
]);

$team = Team::create([
    'name' => $user->email,
    'owner_id' => $user->id,
]);
$team->users()->attach($user, ['role' => 'owner']);

Is the freeTeamPlan activated by default? How can I apply a billing plan now?

0 likes
4 replies
obs's avatar
Level 3

I'm wondering if the code I have is correct and was also wondering how to apply a billing plan to a team. I found, that there is also a SparkUser, not only User. So that's what I'm confused about. Should I create a user the way shown above or do I need to use SparkUser?

bugsysha's avatar

Your code looks fine. Bit strange that you are using user's email as a name for the team. I can not tell you how to do it in code that I have no insight into, not sure if anyone can.

Please or to participate in this conversation.