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\Requests\ImageUploadRequest;
use App\Models\Actionlog;
use App\Models\Manufacturer;
use App\Http\Requests\UploadFileRequest;
use Illuminate\Support\Facades\Log;
use App\Models\Asset;
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);
@ -895,19 +895,10 @@ class AssetsController extends Controller
if ($asset->isValid() && $asset->save()) {
$file_name = '';
// Upload an image, if attached
// Create the image (if one was chosen.)
if ($request->hasFile('image')) {
$path = 'private_uploads/audits';
if (! Storage::exists($path)) {
Storage::makeDirectory($path, 775);
$file_name = $request->handleFile('private_uploads/audits/', 'audit-'.$asset->id, $request->file('image'));
}
$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);
return redirect()->route('assets.audit.due')->with('success', trans('admin/hardware/message.audit.success'));