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

EventFellows's avatar

Make team field optional/ remove from registration form

For users it feels weird that a Team Name is required when signing up - many people's preference would be to have a user signup with as few fields as possible but still offer team functionality once a user is registered.

I see three steps to achive this.

  1. remove the 'required' validation from \Interactions\Auth\CreateUser.php in vendor folder (around line 20)
  2. disable the 'hasTeam' middleware in app\Providers\RouteServiceProvider.php in method mapWebRoutes() so users do not get reminded of not having a team all the time
  3. (optional) change display/ hiding of team field in resources\views\vendor\spark\auth\register-common-form.blade.php

Is there a better/ cleaner way of removing the 'required' aspect from the team field? Especially as 1. resides in the vendor forlder that I would rather not touch.

Has anyone had any luck with something similar to the Spark::swap approach maybe..?

(this works in the booted() medhot of SparkServiceController for the other basic fields but not for 'team'

        // replace default rules for user registration / does not apply for team field
        Spark::swap('CreateUser@rules', function () {
            return [
                'name' => 'required|max:4',
            ];
        });

I am aware of the other solution marked as complete here that feels a bit hacky in the way it is done, see here: https://laracasts.com/discuss/channels/spark/remove-team-field-from-signup-form

0 likes
3 replies
pascalb's avatar

Hey this is the way I did it.

First, when you use the CanJoinTeam on your user class, the team registration is hard coded in the namespace Laravel\Spark\Interactions\Auth\CreateUser class

class CreateUser implements Contract
{
    /**
     * {@inheritdoc}
     */
    public function validator($request)
    {
        $validator = $this->baseValidator($request);

    // here
        $validator->sometimes('team', 'required|max:255', function ($input) {
            return Spark::usesTeams() && ! isset($input['invitation']);
        });

        return $validator;
    }

To disable this, I extended the class and overwrite this method like this :

use Laravel\Spark\Interactions\Auth\CreateUser;

class CreateUserExtended extends CreateUser
{
    /**
     * Remove the team validation force registration
     */
    public function validator($request)
    {
        return $this->baseValidator($request);
    }

}

Then I used the Spark::swap to replace the original behaviour with my custom method in SparkServiceProvider

// don't force team registration on user creation

        Spark::swap('CreateUser@validator', function ($request) {

            $user = new CreateUserExtended();

            return $user->validator($request);
        });

This way, if the baseValidator method is updated in the futur, you wont loose the changes.

After that, you will passed the Validation part, but your user will have an empty team assigned to it, if you want to disabled this, you have to apply the same logic to overwrite the handle method on the namespace Laravel\Spark\Interactions\Auth\Register method.

Basically because, like in the validator, the condition if the user uses teams is hard coded

    /**
     * Create the user for the new registration.
     *
     * @param  RegisterRequest  $request
     * @return \Illuminate\Contracts\Auth\Authenticatable
     */
    protected function createUser(RegisterRequest $request)
    {
        $user = Spark::interact(CreateUserContract::class, [$request]);

      // here
        if (Spark::usesTeams()) {
            $this->configureTeamForNewUser($request, $user);
        }

        return $user;
    }

Since the logic is similar, I'll just paste the code.

use Laravel\Spark\Spark;
use Laravel\Spark\Interactions\Auth\Register;
use Laravel\Spark\Contracts\Http\Requests\Auth\RegisterRequest;
use Laravel\Spark\Contracts\Interactions\Auth\CreateUser as CreateUserContract;

class RegisterExtended extends Register
{
    /**
     * Create the user for the new registration.
     *
     * @param  RegisterRequest  $request
     * @return \Illuminate\Contracts\Auth\Authenticatable
     */
    public function createUser(RegisterRequest $request)
    {
        return Spark::interact(CreateUserContract::class, [$request]);
    }

    /**
     * Subscribe the given user to a subscription plan.
     * Parent method visibility is protected
     * You need to make it public to call it in SparkServiceProvider
     *
     * @param  RegisterRequest  $request
     * @param  \Illuminate\Contracts\Auth\Authenticatable  $user
     * @return \Illuminate\Contracts\Auth\Authenticatable
     */
    public function subscribe($request, $user)
    {
        return parent::subscribe($request, $user);
    }
}
class SparkServiceProvider extends ServiceProvider {

    public function register() {
        
        parent::register();

        // don't force team registration on user creation

        Spark::swap('Register@handle', function(RegisterRequest $request) {

            return DB::transaction(function () use ($request) {
                
                $register = new RegisterExtended();
                
                return $register->subscribe($request, $register->createUser($request));
            });
        });

        Spark::swap('CreateUser@validator', function ($request) {

            $user = new CreateUserExtended();

            return $user->validator($request);
        });
    }

After that, disable the hasTeam middleware like you said and remove/comment the team input field in the register-common-form.blade.php and you should be good to go.

Hope it helps you, I personally prefer this option, it feels more natural to me.

2 likes
beetuco's avatar

Bit of a hack but to 'Wizard of Oz it', I added the following to register-stripe.js

// If Name is present but Team name is present - just use the Name provided and append " Team". 
            if (this.registerForm.name && ! this.registerForm.team) {
                this.registerForm.team = this.registerForm.name.concat(" Team")
            }
1 like
Nicholaus's avatar

I used a computed property and a watcher to set the team name to whatever name the user enters:

    computed: {
        registerName() {
            return this.registerForm.name;
        }
    },

    watch: {
        registerName(name) {
            this.registerForm.team = name;
        }
    },
1 like

Please or to participate in this conversation.