Exemplo n.º 1
0
 /**
  * @param  LinkMany      $link
  */
 public function update(LinkMany $link)
 {
     foreach ($link->getAdded() as $added) {
         $added->{$this->getForeignKey()} = $link->getModel()->{$this->getKey()};
     }
     foreach ($link->getRemoved() as $added) {
         $added->{$this->getForeignKey()} = null;
     }
 }
Exemplo n.º 2
0
 public function insert(LinkMany $link)
 {
     $inserted = new Models();
     if (count($link->getAdded()) > 0) {
         $through = $link->getModel()->getLink($this->through);
         $repo = $this->getThroughRepo();
         foreach ($link->getAdded() as $added) {
             $inserted->add($repo->newModel([$this->getKey() => $link->getModel()->getId(), $this->getForeignKey() => $added->getId()]));
         }
         $through->get()->addAll($inserted);
     }
     return $inserted;
 }