Skip to content

Instantly share code, notes, and snippets.

@localdisk
Created December 29, 2019 10:43
Show Gist options
  • Save localdisk/bbdf15ef6d3ce1928c305815df08f6e1 to your computer and use it in GitHub Desktop.
Save localdisk/bbdf15ef6d3ce1928c305815df08f6e1 to your computer and use it in GitHub Desktop.
User Role sample.
<?php
class Role extends Model
{
public function users()
{
// permissions まで含めると morphedByMany がよさそう
return $this->belongsToMany(User::class);
}
}
<?php
class User extends Authenticatable
{
public function roles()
{
return $this->belongsToMany(Role::class);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment