} /** * @return mixed */ public function cloneDocument() { $document = Document::createNew($this); $document->path = $this->path; $document->preview = $this->preview; $document->name = $this->name; $document->type = $this->type; $document->disk = $this->disk; $document->hash = $this->hash; $document->size = $this->size; $document->width = $this->width; $document->height = $this->height; return $document; } } Document::deleted(function ($document) { $same_path_count = DB::table('documents')->where('documents.account_id', '=', $document->account_id)->where('documents.path', '=', $document->path)->where('documents.disk', '=', $document->disk)->count(); if (!$same_path_count) { $document->getDisk()->delete($document->path); } if ($document->preview) { $same_preview_count = DB::table('documents')->where('documents.account_id', '=', $document->account_id)->where('documents.preview', '=', $document->preview)->where('documents.disk', '=', $document->disk)->count(); if (!$same_preview_count) { $document->getDisk()->delete($document->preview); } } });