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

dpet's avatar
Level 5

Is there a way to have user roles and allow eloquent relationships between them?

Most suggestions say that keeping all of your users in one table and model is best. What if you want to have roles where some users of a type belong to other users? Should these be kept in separate tables and models?

0 likes
1 reply
Indemnity83's avatar
Level 22

A model can relate to itself; just setup a nullable boss_id column (or similar) on your users table then define the relationship pair in the users model

public function boss()
{
    return $this->belongsTo(Self::class);
}

public function staff()
{
    return $this->hasMany(Self::class, 'boss_id');
}

Please or to participate in this conversation.