You can choose to do 2 relationships, a many-to-many and a one-to-many.
Or use a single relationship a many-to-many and flag the type of the relationship in the pivot table.
Personally I would go with two relationships if there could be a single owner of the Project and type of members in a Project doesn't have high importance.
The project will only have one owner and members will not have different levels of importance (sticking to basics at the moment).
If I understand correctly would you suggest that User and Project have a many to many relationship and Project has a belongs to relationship with User?
Something like...
<?php
class User extends Eloquent
{
public function ownedProjects()
{
return $this->hasMany('Project', 'owner');
}
public function joinedProjects()
{
return $this->belongsToMany('Project');
}
}
<?php
class Project extends Eloquent
{
public function owner()
{
return $this->belongsTo('User', 'owner');
}
public function members()
{
return $this->belongsToMany('User');
}
}
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community