Skip to content

A free open source IT asset/license management system

Better surface errors on invalid assets

snipe1c6e022ee20e
diff --git a/app/Http/Controllers/Assets/AssetCheckinController.php b/app/Http/Controllers/Assets/AssetCheckinController.php
index 7e58b812d6..b3c48c167f 100644
--- a/app/Http/Controllers/Assets/AssetCheckinController.php
+++ b/app/Http/Controllers/Assets/AssetCheckinController.php
@@ -48,7 +48,15 @@ class AssetCheckinController extends Controller
$asset->setRules($asset->getRules() + $asset->customFieldValidationRules());
if ($asset->isInvalid()) {
- return redirect()->route('hardware.edit', $asset)->withErrors($asset->getErrors());
+ // Also flash the specific error messages so they surface
+ // in the top alert on the edit page. Without this, model-
+ // level rules that fail on a field the edit form doesn't
+ // render (or is scrolled off-screen) leave the user with
+ // a generic "check the form" message and nothing visibly
+ // highlighted. See notifications.blade.php multi_error_messages.
+ return redirect()->route('hardware.edit', $asset)
+ ->withErrors($asset->getErrors())
+ ->with('multi_error_messages', $asset->getErrors()->all());
}
$target_option = match ($asset->assigned_type) {
@@ -215,8 +223,13 @@ class AssetCheckinController extends Controller
->with('success', trans('admin/hardware/message.checkin.success'));
}
- // Redirect to the asset management page with error
- return redirect()->route('hardware.index')->with('error', trans('admin/hardware/message.checkin.error').$asset->getErrors());
+ // Redirect to the asset management page with error. Flash the
+ // specific validation messages via multi_error_messages so the
+ // user sees WHAT failed instead of the previous stringified
+ // MessageBag concatenation.
+ return redirect()->route('hardware.index')
+ ->with('error', trans('admin/hardware/message.checkin.error'))
+ ->with('multi_error_messages', $asset->getErrors()->all());
}
/**
diff --git a/app/Http/Controllers/Assets/AssetCheckoutController.php b/app/Http/Controllers/Assets/AssetCheckoutController.php
index b90415c411..d78e7ba4b2 100644
--- a/app/Http/Controllers/Assets/AssetCheckoutController.php
+++ b/app/Http/Controllers/Assets/AssetCheckoutController.php
@@ -45,7 +45,13 @@ class AssetCheckoutController extends Controller
$asset->setRules($asset->getRules() + $asset->customFieldValidationRules());
if ($asset->isInvalid()) {
- return redirect()->route('hardware.edit', $asset)->withErrors($asset->getErrors());
+ // Also flash the specific validation messages via
+ // multi_error_messages so they surface in the top alert
+ // on the edit page. See the matching block in
+ // AssetCheckinController::create() for the reasoning.
+ return redirect()->route('hardware.edit', $asset)
+ ->withErrors($asset->getErrors())
+ ->with('multi_error_messages', $asset->getErrors()->all());
}
if ($asset->availableForCheckout()) {
@@ -172,10 +178,17 @@ class AssetCheckoutController extends Controller
->with('success', trans('admin/hardware/message.checkout.success'));
}
- // Redirect to the asset management page with error
- return redirect()->route('hardware.checkout.create', $asset)->with('error', trans('admin/hardware/message.checkout.error').$asset->getErrors());
+ // Redirect back to the checkout form with the specific
+ // validation messages surfaced via multi_error_messages
+ // (replaces the previous stringified MessageBag concat).
+ return redirect()->route('hardware.checkout.create', $asset)
+ ->with('error', trans('admin/hardware/message.checkout.error'))
+ ->with('multi_error_messages', $asset->getErrors()->all());
} catch (ModelNotFoundException $e) {
- return redirect()->back()->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())
+ ->with('multi_error_messages', $asset->getErrors()->all());
} catch (CheckoutNotAllowed $e) {
return redirect()->back()->with('error', $e->getMessage());
}