示例#1
0
文件: User.php 项目: larrytech/auth
 /**
  * Assign a user to a given role.
  *
  * @param mixed $role The role.
  * @return \Larrytech\Auth\Models\Role
  * @throws \InvalidArugmentException
  * @throws \Larrytech\Auth\Models\DuplicateRoleException
  */
 public function assignRole($role)
 {
     if ($role == null) {
         throw new InvalidArgumentException();
     }
     if ($this->hasRole($role)) {
         throw new DuplicateRoleException();
     }
     if ($role instanceof Role) {
         return $this->roles()->save($role);
     }
     if ($relation = Role::whereName($role)->first()) {
         return $this->roles()->save($relation);
     }
     return $this->roles()->save(Role::create(array('name' => $role)));
 }
示例#2
0
 /**
  * {@inheritDoc}
  */
 public function update(Role $role, array $attributes = array())
 {
     $role->fill($attributes);
 }
示例#3
0
 public function testRoleFillableAttributesAreFillable()
 {
     $r = new Role(array('name' => 'admin'));
     $this->assertEquals('admin', $r->getName());
 }