Skip to content

A free open source IT asset/license management system

Redirect to back on bad checkout

snipeb6c258bb12ae
diff --git a/app/Http/Controllers/AssetsController.php b/app/Http/Controllers/AssetsController.php
index d87980cd22..4e020e52e0 100755
--- a/app/Http/Controllers/AssetsController.php
+++ b/app/Http/Controllers/AssetsController.php
@@ -459,11 +459,13 @@ class AssetsController extends Controller
}
$this->authorize('checkout', $asset);
$admin = Auth::user();
-
+
+
// This item is checked out to a location
if (request('checkout_to_type')=='location') {
$target = Location::find(request('assigned_location'));
$asset->location_id = ($target) ? $target->id : '';
+
} elseif (request('checkout_to_type')=='asset') {
$target = Asset::where('id','!=',$assetId)->find(request('assigned_asset'));
$asset->location_id = $target->rtd_location_id;
@@ -471,16 +473,16 @@ class AssetsController extends Controller
if ($target->location_id!='') {
$asset->location_id = ($target) ? $target->location_id : '';
}
- } else {
+
+ } elseif (request('checkout_to_type')=='user') {
// Fetch the target and set the asset's new location_id
$target = User::find(request('assigned_user'));
$asset->location_id = ($target) ? $target->location_id : '';
}
-
// No valid target was found - error out
if (!$target) {
- return redirect()->to("hardware/$assetId/checkout")->with('error', trans('admin/hardware/message.checkout.error'))->withErrors($asset->getErrors());
+ return redirect()->back()->with('error', trans('admin/hardware/message.checkout.error'))->withErrors($asset->getErrors());
}