/** * Get the changes. * * @param \Illuminate\Database\Eloquent\Collection $saved * * @return array */ private function getChanges($saved) { return Comparator::compare($this->data->map(function (array $settings) { return Arr::dot($settings); })->toArray(), $saved->groupBy('domain')->map(function ($item) { /** @var \Illuminate\Database\Eloquent\Collection $item */ return $item->lists('casted_value', 'key'); })->toArray()); }
/** * Compare the deleted entries. * * @return array */ private function getDeleted() { if ($this->unsaved->isEmpty()) { // Delete all saved settings. return $this->saved->map(function (array $settings) { return array_keys($settings); })->toArray(); } $deleted = []; foreach ($this->unsaved as $domain => $values) { $diff = array_diff(array_keys($this->saved->get($domain, [])), array_keys($values)); if (!empty($diff)) { $deleted[$domain] = $diff; } } return $deleted; }