code: 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);
      }
docs: Attach relation
  
  @return \Illuminate\Database\Eloquent\Model;