Use Storage for file uploads (not model images)

This commit is contained in:
snipe 2018-07-25 11:57:49 -07:00
parent a9fd9c9e59
commit 373885ebd1
3 changed files with 19 additions and 16 deletions

View file

@ -107,21 +107,18 @@ class AssetFilesController extends Controller
{
$asset = Asset::find($assetId);
$this->authorize('update', $asset);
$destinationPath = config('app.private_uploads').'/imports/assets';
$rel_path = 'storage/private_uploads/assets';
// the asset is valid
if (isset($asset->id)) {
$this->authorize('update', $asset);
$log = Actionlog::find($fileId);
$full_filename = $destinationPath.'/'.$log->filename;
if (file_exists($full_filename)) {
\Log::debug('Trying to delete '.$full_filename);
Storage::delete($full_filename);
//unlink($destinationPath.'/'.$log->filename);
if (file_exists(base_path().'/'.$rel_path.'/'.$log->filename)) {
Storage::delete($rel_path.'/'.$log->filename);
}
$log->delete();
return redirect()->back()->with('success', trans('admin/hardware/message.deletefile.success'));
return redirect()->back()
->with('success', trans('admin/hardware/message.deletefile.success'));
}
// Redirect to the hardware management page

View file

@ -75,19 +75,19 @@ class LicenseFilesController extends Controller
public function destroy($licenseId = null, $fileId = null)
{
$license = License::find($licenseId);
$destinationPath = config('app.private_uploads').'/licenses';
// the license is valid
$rel_path = 'storage/private_uploads/licenses';
// the asset is valid
if (isset($license->id)) {
$this->authorize('edit', $license);
$this->authorize('update', $license);
$log = Actionlog::find($fileId);
$full_filename = $destinationPath.'/'.$log->filename;
if (file_exists($full_filename)) {
Storage::delete($full_filename);
// unlink($destinationPath.'/'.$log->filename);
if (file_exists(base_path().'/'.$rel_path.'/'.$log->filename)) {
Storage::delete($rel_path.'/'.$log->filename);
}
$log->delete();
return redirect()->back()->with('success', trans('admin/licenses/message.deletefile.success'));
return redirect()->back()
->with('success', trans('admin/hardware/message.deletefile.success'));
}
// Redirect to the licence management page

View file

@ -42,6 +42,7 @@
"watson/validating": "^3.0"
},
"require-dev": {
"barryvdh/laravel-ide-helper": "^2.4",
"codeception/codeception": "^2.4",
"filp/whoops": "~2.0",
"fzaninotto/faker": "~1.4",
@ -72,6 +73,11 @@
]
},
"scripts": {
"post-update-cmd": [
"Illuminate\\Foundation\\ComposerScripts::postUpdate",
"php artisan ide-helper:generate",
"php artisan ide-helper:meta"
],
"post-autoload-dump": [
"Illuminate\\Foundation\\ComposerScripts::postAutoloadDump",
"@php artisan package:discover"