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

huskeyweb's avatar

Needing your thoughts on adding and removing team users in Spark

I am creating a SAAS app using Spark and would like some of your thoughts on how to manage team users. I will be using team billing and will charge $6 per user per month.

Team owners will need the ability to add or remove users at any time. The app is for accountants who will likely add temporary employees during tax season and remove them immediately after tax season. But I want the data created by removed users to still be available in the app.

For example, an accountant may want to run a report on how much time the removed user spent on a particular client during April for billing purposes. So the removed user's data should remain available in the system.

Spark adds an entry to the "team_users" table when a user is added and removes that entry when the user is removed.

I am thinking about 2 options to accomplish this:

#1 Use soft deletes on the "team_users" table. I believe this will require me to modify the Spark source code and I'm not really sure where to start with that.

I also need to use the Spark events, TeamMemberAdded and TeamMemberRemoved to increment and decrement the user quantity for a subscription.

#2 Create a new role called "inactive" in addition to the "Owner" and "Member" roles that are already available. Then I would allow the team owner to change a user's role to "inactive".

I could still use the Spark TeamMemberAdded event to increment the subscription when a brand new user is added. I would need an event to decrement the subscription quantity when a user is made "inactive". I would also need another event to increment the subscription when a team member is made "active" again.

I guess I could write a middleware to deny access to all routes if a user has a role of "inactive".

I'm using Laravel 5.2 and Spark 1.0.14.

If you have done something similar or have any thoughts about this please let me know.

0 likes
4 replies
J_shelfwood's avatar

If you dont like editing the source code then using the roles does sound kind of okay to me. It's not the best way to go about it but I feel you if that's a trade-off you wish to make.

I would just have the active role and leave the inactive role out, assuming that if there is no 'active' role present that the account is inactive anyway.

I haven't got any experience using spark so there might be an easier way of going about this. Not sure.

huskeyweb's avatar

Your response got me thinking about another possible way to do this.

Instead of using roles I could just add another column to the "team_users" table called "inactive". This column would have a default value of 0. The administrator could then click a button that would update that user's "inactive" column to 1.

Then I would use a middleware to disallow access to the user if their "inactive" column is equal to 1.

This may be a better user experience also.

The main reason I don't want to edit the source code is because I want to be able to update Spark with Composer without affecting my changes.

Thanks for your thoughts on this.

Cronix's avatar

@huskeyweb That will likely also mess up the maxTeamSize settings, if you are using those. Like if you don't want a certain team plan to be able to have more than 10 users on a team, so you'd probably need to incorporate that logic, too, since spark won't take your modifications into account and just does a count() on the team users.

Also, you don't need to (shouldn't!!) modify core files. I just copy the ones I need to modify into app/SparkExtensions (arbitrary location), rename them, have the class extend the original class, modify them how I need and then bind my implementation in the ioc so laravel will use my custom class instead of the original. So when it's upgrade time, it doesn't matter if spark overwrites the original files since my modifications aren't contained in there.

Edit: see my response in this post for more on how I do that

huskeyweb's avatar

At the moment I'm not planning on limiting a team's size. So I don't think I will need to use maxTeamMembers for that.

Are there any other situations in Spark that require maxTeamMembers to be accurate that you know of?

Also, thanks for the explanation of how to overwrite a Spark class.

Please or to participate in this conversation.