/** * 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))); }
/** * {@inheritDoc} */ public function update(Role $role, array $attributes = array()) { $role->fill($attributes); }
public function testRoleFillableAttributesAreFillable() { $r = new Role(array('name' => 'admin')); $this->assertEquals('admin', $r->getName()); }