/** * Listen to Upload * * Observe Uploadable models for changes. Should be called from the boot() method. * @return void */ protected function listenToUpload() { if (!($model = $this->getModelClass())) { return; } if (Config::get('app.debug')) { Log::debug('Binding upload relationship caches', ['uploadable' => $model]); } $flush_uploadable = function ($uploadable) { $repository = $this->make($uploadable); $tags = $repository->getTags('uploads'); if (Config::get('app.debug')) { Log::debug('Flushing uploadable relationship caches', ['uploadable' => $repository->id, 'tags' => $tags]); } Cache::tags($tags)->flush(); }; $model::updated($flush_uploadable); $model::deleted($flush_uploadable); $flush_upload = function ($upload) use($model) { $repository = Upload::make($upload); $tags = $repository->getTags($model); if (Config::get('app.debug')) { Log::debug('Flushing upload relationship caches', ['model' => $model, 'tags' => $tags]); } Cache::tags($tags)->flush(); foreach ($this->withUpload($repository) as $uploadable) { $uploadable->getModel()->touch(); } }; $upload_model = Upload::getModelClass(); $upload_model::updated($flush_upload); $upload_model::deleted($flush_upload); }
/** * @inheritDoc */ public function uploads() { return $this->morphMany(Upload::getModelClass(), 'uploadable'); }