From b6c258bb12aeeb889ae64b0c7ad1b190b0c2646b Mon Sep 17 00:00:00 2001 From: snipe Date: Mon, 27 Nov 2017 21:19:50 -0800 Subject: [PATCH] Redirect to back on bad checkout --- app/Http/Controllers/AssetsController.php | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) 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()); }