Skip to content

Instantly share code, notes, and snippets.

@matthewtrask
Created March 11, 2021 02:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save matthewtrask/1ea2bd26e36e6df7b235ba700ce4979c to your computer and use it in GitHub Desktop.
Save matthewtrask/1ea2bd26e36e6df7b235ba700ce4979c to your computer and use it in GitHub Desktop.
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