function mitterDeepArrayFilter($array) { $array = array_filter($array, 'mitterNullFilter'); foreach ($array as $key => $item) { if (is_array($item)) { $array[$key] = mitterDeepArrayFilter($item); } } return $array; }
public function MorphToMany($name, $data = array()) { $data = mitterDeepArrayFilter($data); $allRelations = $this->model->{$name}; $inputedRelations = $this->newRelationsCollector($name, $data); $newRelations = $inputedRelations->diff($allRelations); $oldRelations = $allRelations->diff($inputedRelations); if (!$oldRelations->isEmpty()) { call_user_func(array($this->model, $name))->detach($oldRelations->lists('id')->toArray()); } if (!$newRelations->isEmpty()) { call_user_func(array($this->model, $name))->attach($newRelations->lists('id')->toArray()); } }