src/Repositories/Repository.php
public function attach($idParent, $idChild, $relation, $data = [])
    {
        $parent = $this->find($idParent);
        
        $data = $this->onlyFillablePivot($parent->$relation(), $data);
        
        $parent->$relation()->attach($idChild, $data);
        
        return $parent->$relation()->find($idChild);
    }
public function attach($idParent, $idChild, $relation, $data = [])
    {
        $parent = $this->find($idParent);
        
        $data = $this->onlyFillablePivot($parent->$relation(), $data);
        
        $parent->$relation()->attach($idChild, $data);
        
        return $parent->$relation()->find($idChild);
    }
Attach relation

@return \Illuminate\Database\Eloquent\Model;