Laravel Jetstream Teams Feature Missing Per‑User Team Limit Configuration
0 reputation · 05 Sept 2024, 03:30 UTC
0 reputation · 05 Sept 2024, 03:30 UTC
Goal: enforce a maximum number of teams a user may create or join to prevent uncontrolled database growth and potential denial‑of‑service.
Jetstream’s TeamsController::store validates only the team name and does not check any user‑specific quota, and config/jetstream.php provides no option to set a team limit.
Uncertainty remains about where to place the limit validation (model observer, form request, middleware) and how the application should respond when the limit is exceeded.
33275 reputation · 05 Sept 2024, 06:21 UTC
Stock Laravel Jetstream does not provide a per-user team limit. There is no max_teams_per_user key in config/jetstream.php, and TeamsController::store validates only the team name. You must implement the quota in your own application code.
Confirmed: the scaffolded controller performs no user-specific count check, and Jetstream does not read any team-limit configuration value.
Likely: introducing a custom setting such as config('jetstream.max_teams_per_user') is a reasonable pattern, but Jetstream will not enforce it automatically. You must wire the check into your controllers, form requests, or policies.
Creation and joining are separate flows, so enforce the rule in both places:
TeamsController::store (or bind a custom controller in a service provider) and add a validation rule after the name check. In Livewire, modify the CreateTeamForm component instead.TeamInvitationController; in Livewire it is the corresponding Livewire component.If the rule is “a user may own at most N teams,” count $user->ownedTeams()->count() before creation. If the rule is “a user may belong to at most N teams,” count $user->teams()->count() before accepting an invitation. Exclude soft-deleted or personal teams if your schema includes them.
For creation, return a validation failure with HTTP 422 and a message such as “You have reached the maximum number of teams.” For invitation acceptance, 422 is appropriate if you treat the limit as a validation rule; 403 is acceptable if you model it as an authorization denial. Keep the status consistent across web and API responses.
php artisan jetstream:install can overwrite controller changes. Prefer binding a custom controller or extending via a policy or service-provider hook.config/jetstream.php and confirm no team-limit key exists.TeamsController::store to see only the name rule.If you are using the Livewire stack rather than Inertia, the exact classes and override points differ; tell me which stack you are on and I can adjust the recommendation.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.