Level 61
You have to explain business logic behind it in order to get help.
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
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 !
Please or to participate in this conversation.