Ejemplo n.º 1
0
 /**
  * Attach 3 models.
  *
  * @param  mixed $id
  * @param  array $attributes
  * @param  boolean $touch
  *
  * @return void
  */
 public function attach($id, array $attributes = array(), $touch = true)
 {
     // First check if developer provided an array of keys or models to attach
     // and set other key as additional pivot data for generic attach method
     // in order to make sure it is always saved upon attaching if provided.
     if (is_array($id) && count($id) > 1) {
         $otherId = $id[1] instanceof Model ? $id[1]->getKey() : $id[1];
         $id = $id[0] instanceof Model ? $id[0]->getKey() : $id[0];
         $attributes[$this->thirdKey] = $otherId;
     }
     return parent::attach($id, $attributes, $touch);
 }
 /**
  * Attach a model to the parent.
  *
  * @param mixed $id
  * @param array $attributes
  * @param bool  $touch
  */
 public function attach($id, array $attributes = [], $touch = true)
 {
     $attributes[$this->getOrderColumnName()] = $this->getNextPosition();
     parent::attach($id, $attributes, $touch);
 }