Support the ongoing development of Laravel.io →
Database Eloquent
Last updated 2 years ago.
0

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.

Last updated 2 years ago.
0

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?

Last updated 2 years ago.
0

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');
    }
}
Last updated 2 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.