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

oliverbusk's avatar

Spark - Eloquent Relationships for Teams

Hi all

I am currently trying to create a simple SaaS application, where teams can create projects. I am currently stuck at the migration, because I am unsure if the user or the team should "own" the project?

For example, I would normally do this:

User.php:

public function projects()
{
     return $this->hasMany('App\Projects');
}

Project.php:

public function user()
{
     return $this->belongsTo('App\User');
}

So in above case, the user can have many projects and a project belongs to an user.

How should I do this in Laravel Spark with teams?

0 likes
3 replies
Braunson's avatar

Well this depends on what you want to do? Do you need to know which user from X team created it? Are you using that information (the user of the project) for any reason? If yes record both the user and team, otherwise just stick with the team.

oliverbusk's avatar

Let's say I am part of a team, that have 10 other members. I (my user) have created a lot of projects, but some day, I am kicked out of the team. In this case, I do not want the projects to be associated with my user, but rather the team.

Hope it makes sense!

steve_laracasts's avatar

I will probably have to look at this at some point, my instinct tells me that projects should be migrated to another user in the same team rather than trying to associate projects with a team; this could be part of the delete user routine. It seems like this would simply be a case of changing the owner of the project based on what I have learned about Spark so far (not that much).

Workflow wise, I would do this in much the same way as you may have experienced transferring a domain name to another users account. Namecheap have an excellent process for doing just this if you would like to look at an example.

Good luck!

If you have already found a way to do this would you please share your solution?

Please or to participate in this conversation.