belongsToMany('App\Role'); } public function assignRole($role) { return $this->roles()->attach($role); } public function revokeRole($role) { return $this->roles()->detach($role); } public function hasRole($name) { foreach ($this->roles as $role) { if ($role->name === $name) { return true; } return false; } } }