Laratrust\Traits\LaratrustUserTrait::attachRole PHP Метод

attachRole() публичный Метод

Alias to eloquent many-to-many relation's attach() method.
public attachRole ( mixed $role, $group = null ) : Illuminate\Database\Eloquent\Model
$role mixed
Результат Illuminate\Database\Eloquent\Model
    public function attachRole($role, $group = null)
    {
        if (is_object($role)) {
            $role = $role->getKey();
        }
        if (is_array($role)) {
            $role = $role['id'];
        }
        if (!is_object($group) && $group != null) {
            throw new InvalidArgumentException();
        }
        if (!is_null($group)) {
            $group = $group->getKey();
        }
        $this->roles()->wherePivot(Config::get('laratrust.group_foreign_key'), $group)->detach($role);
        $this->roles()->attach($role, [Config::get('laratrust.group_foreign_key') => $group]);
        $this->flushCache();
        return $this;
    }