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

eggplantSword's avatar

Create relationships for group with teacher / students

I'm trying to create the relationships between the models Group and User something like this but I'm unsure how to do it

Group
// I'm not sure if there are better in the GroupUsers Model or not

public function teacher()
{
    return $this->hasOne(User::class)->where(// check for user_type here of the group users and return the user type is 4)
}

public function students()
{
    return $this->hasMany(User::class)->where(// check for user_type here of the group users and return the user type is 5)
}

User

//this is the relationship I already have which gets all the group users
public function groupUser()
    {
        return $this->hasMany(GroupUsers::class);
    }

Any help is greatly appreciated !

0 likes
2 replies
bugsysha's avatar

You have to explain business logic behind it in order to get help.

Azeem812's avatar

Please explain your shortly business logic,so i know what you want to do?

Please or to participate in this conversation.