@MThomas something very rough and I mean very rough for you to play with if you want to use this approach (not implemented just a direction ):
Create a very basic RoleInterface. Keep your RoleRepositoryInterface seperate, just a RoleUserInterface that you use for binding purposes only.
Keep it simple, some sort of basic mutual methods example getRole, hasRole and if you want addRole, although that seems not to be a great fit for User, but your call.
Bind RoleInterface to Role(model) in a Service provider
Then implement the RoleInterface into your User model vs. construct inject RoleInterface
In User model:
protected static $rolesModel = 'Role'; // your model
// setup relationship
public function roles()
{
return $this->belongsToMany(static::Role, 'users_roles', 'user_id', 'role_id')->withTimestamps();
}
//
public function getRoles()
{
return $this->roles;
}
public function hasRole($role)
{
// you would need to set $instance, but you might be able to inject ::class, don't know play around
$role = array_first($this->roles, function($idx, $instance) use ($role)
{
if ($role instanceof RoleInterface)
{
return ($instance->getRoleId() === $role->getRoleId());
}
return false;
});
return $role, // whatever you want to
}