Use UploadFileRequest for audit files

Signed-off-by: snipe <snipe@snipe.net>
This commit is contained in:
snipe 2024-05-15 15:43:38 +01:00
parent 71b5bf2eef
commit 8310b91e00

View file

@ -6,7 +6,7 @@ use App\Helpers\Helper;
use App\Http\Controllers\Controller; use App\Http\Controllers\Controller;
use App\Http\Requests\ImageUploadRequest; use App\Http\Requests\ImageUploadRequest;
use App\Models\Actionlog; use App\Models\Actionlog;
use App\Models\Manufacturer; use App\Http\Requests\UploadFileRequest;
use Illuminate\Support\Facades\Log; use Illuminate\Support\Facades\Log;
use App\Models\Asset; use App\Models\Asset;
use App\Models\AssetModel; use App\Models\AssetModel;
@ -863,7 +863,7 @@ class AssetsController extends Controller
} }
public function auditStore(Request $request, $id) public function auditStore(UploadFileRequest $request, $id)
{ {
$this->authorize('audit', Asset::class); $this->authorize('audit', Asset::class);
@ -895,20 +895,11 @@ class AssetsController extends Controller
if ($asset->isValid() && $asset->save()) { if ($asset->isValid() && $asset->save()) {
$file_name = ''; // Create the image (if one was chosen.)
// Upload an image, if attached
if ($request->hasFile('image')) { if ($request->hasFile('image')) {
$path = 'private_uploads/audits'; $file_name = $request->handleFile('private_uploads/audits/', 'audit-'.$asset->id, $request->file('image'));
if (! Storage::exists($path)) {
Storage::makeDirectory($path, 775);
}
$upload = $image = $request->file('image');
$ext = $image->getClientOriginalExtension();
$file_name = 'audit-'.str_random(18).'.'.$ext;
Storage::putFileAs($path, $upload, $file_name);
} }
$asset->logAudit($request->input('note'), $request->input('location_id'), $file_name); $asset->logAudit($request->input('note'), $request->input('location_id'), $file_name);
return redirect()->route('assets.audit.due')->with('success', trans('admin/hardware/message.audit.success')); return redirect()->route('assets.audit.due')->with('success', trans('admin/hardware/message.audit.success'));
} }