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

mariohbrino's avatar

Larave Spark to define which users can create team

There is a method I can use to define if the users can create teams named noAdditionalTeams, which it can be add at SparkServiceProvider.php to define all users cannot create a team.

There is a way to I define which user can create team or cannot?

0 likes
6 replies
Cronix's avatar

There is a way to I define which user can create team or cannot?

No, it's just a site-wide setting. On or off for all.

1 like
Cronix's avatar
Cronix
Best Answer
Level 67

It might be possible to check the user in middleware and enable Spark::noAdditionalTeams() if they don't meet your criteria. I haven't tried that.

1 like
mariohbrino's avatar

@Cronix

I add a field into table users to check if the user can create a team, and use a middleware to set the method Spark::noAdditionalTeams, but it doesn't work.

Do you know how can I make it work? Thanks.

if(\Auth::check() && ! $request->user()->create_team && ! Spark::developer(\Auth::user()->email)) {
      Spark::noAdditionalTeams();
}
mariohbrino's avatar

@cmackinlay

You need to define where you want to apply the middleware, in this case I did apply into a group middleware web.

You can add the path of your middleware into app/Http/Kernel.php

protected $middlewareGroups = [
    'web' => [
        \\ ------ code above ------
        \App\Http\Middleware\VerifyUserCanCreateTeam::class,
    ],
]

Please or to participate in this conversation.