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

jordankz's avatar

Adding Registration Fields for Teams

The documentation explains how to create additional registration field for users at registration (https://spark.laravel.com/docs/1.0/adding-registration-fields). However, it does not explain how to do this for teams, which from my searching do not have an identical setup like there exists for users (a Spark::createUsersWith like command).

What is the equivalent process for adding a registration field to the team? For example, in addition to providing 'name', having the user set a team nickname as well upon registering.

Thanks all!

0 likes
4 replies
jordankz's avatar

Found it after some more searching. You want to swap the create function (located in the team repository) so that this (modified to reflect your intended changes) is what you put in your service provider.

        Spark::swap('TeamRepository@create', function ($user, array $data) {
            return Spark::team()->forceCreate([
                'owner_id' => $user->id,
                'name' => $data['name'],
                'trial_ends_at' => Carbon::now()->addDays(Spark::teamTrialDays()),
            ]);
            // Return the team with the given ID...
        });
heykatieben's avatar

Hi there, thanks for this hint, I'm trying to do this now.

I'm still stuck on this. Is this everything you did? Did you update this for the latest Spark?

heykatieben's avatar

Update: I finally got this by doing the above, and also directly updating spark/src/interactions/Auth as follows, below. I tried swapping the function but it didn't work for some reason. I'll update this if I ever figure that out.

public function configureTeamForNewUser(RegisterRequest $request, $user)
    {
        if ($invitation = $request->invitation()) {
            Spark::interact(AddTeamMember::class, [$invitation->team, $user, $invitation->role]);

            self::$team = $invitation->team;

            $invitation->delete();
        } elseif (Spark::onlyTeamPlans()) {
            self::$team = Spark::interact(CreateTeam::class, [
        $user, ['name' => $request->team,
        'slug' => $request->team_slug,
        //my extra data here
            ]);
        } 

        $user->currentTeam();
    }
Cronix's avatar

@heykatieben

and also directly updating spark/src/interactions/Auth

You generally never want to alter any file in /vendor for any package. It will all get overwritten if/when you update spark/the package and you'll have to remember and go and reapply all of your customizations.

I think the easiest solution is to copy spark/src/interactions/Auth/FileYouAltered.php to /app/SparkExtensions/Interactions/Auth/FileYouAltered.php

Then alter that copied file how you need and change the namespace on it to

namespace App\SparkExtensions\Interactions\Auth;

Then in the SparkServiceProviders boot() method, add

$this->app->singleton(
    'Laravel\Spark\Interactions\Auth\FileYouAltered',
    'App\SparkExtensions\Interactions\Auth\FileYouAltered'
);

It will use your class instead of the default, and you can still upgrade via composer without overwriting anything.

1 like

Please or to participate in this conversation.