public function getFileList() { /* * Use deferred bindings */ if ($sessionKey = $this->getSessionKey()) { $list = $deferredQuery = $this->model->{$this->attribute}()->withDeferred($sessionKey)->orderBy('id', 'desc')->get(); } else { $list = $this->model->{$this->attribute}()->orderBy('id', 'desc')->get(); } if (!$list) { $list = new Collection(); } /* * Decorate each file with thumb */ $list->each(function ($file) { $this->decorateFileAttributes($file); }); return $list; }
/** * Saves a collectino of selections * * @param \October\Rain\Support\Collection * @return void */ public function saveSelections(Collection $collection) { // Remove selections not present in the collection $this->selections->each(function ($selection) use($collection) { if (!$collection->contains('id', $selection->id)) { $selection->delete(); } }); // Save the collection $collection->each(function ($selection) { $selection->option_id = $this->id; $selection->save(); }); }