/**
  * Detach models from the relationship.
  *
  * @param array $ids
  * @param bool $touch
  * @return int|void
  */
 public function detach($ids = [], $touch = true)
 {
     if ($ids instanceof Model) {
         $ids = (array) $ids->getKey();
     }
     $query = $this->newPivotQuery();
     // If associated IDs were passed to the method we will only delete those
     // associations, otherwise all of the association ties will be broken.
     // We'll return the numbers of affected rows when we do the deletes.
     $ids = (array) $ids;
     if (count($ids) > 0) {
         $values = $query->whereIn($this->otherKey, (array) $ids)->get();
     }
     parent::detach($ids, $touch);
     // TODO: Change the autogenerated stub
     if (isset($values) && count($values) > 0) {
         //the get method above, returns std objects, so we quickly map them.
         $values = array_map(function ($item) {
             return (array) $item;
         }, $values);
         //fire based on the values, since the $ids can still contain invalid data.
         foreach ($values as $value) {
             app('events')->fire('eloquent.detached: ' . $this->relationName, [$value]);
         }
     }
 }