where('id', $id)->first(); $storagePath = 'peraturan'; if ($file) { $data['file_upload'] = $file->file_upload; if (isset($data['file_document'])) { $oldFilePath = $storagePath . '/' . $file->file_upload; if ($file->file_upload != $data['file_document']->hashName()) { Storage::disk('public')->delete($oldFilePath); } $data['file_upload'] = basename($data['file_document']->store($storagePath, 'public')); } $this->update($file, $data); } else { if (isset($data['file_document'])) { $data['file_upload'] = basename($data['file_document']->store($storagePath, 'public')); } $file = $this->create($data); } return $file; } public function destroy(CmsFilePeraturan $fileData, $storagePath) { if ($fileData) { $oldFilePath = $storagePath . '/' . $fileData->file_upload; Storage::disk('public')->delete($oldFilePath); $this->delete($fileData); } } }