Created
March 11, 2021 02:29
-
-
Save matthewtrask/1ea2bd26e36e6df7b235ba700ce4979c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
users | |
id - integer | |
name - string | |
roles | |
id - integer | |
name - string | |
role_user | |
user_id - integer | |
role_id - integer | |
class User extends Model | |
{ | |
public function roles(): BelongsToMany | |
{ | |
return $this->belongsToMany(Role::class, 'role_user', 'user_id', 'role_id'); | |
} | |
} | |
class Role extends Model | |
{ | |
public function users(): BelongsToMany | |
{ | |
return $this->belongsToMany(User::class, 'role_user', 'role_id', 'user_id'); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment