diff --git a/app/Http/Controllers/Assets/AssetCheckoutController.php b/app/Http/Controllers/Assets/AssetCheckoutController.php index a6d049874a..5671395982 100644 --- a/app/Http/Controllers/Assets/AssetCheckoutController.php +++ b/app/Http/Controllers/Assets/AssetCheckoutController.php @@ -62,9 +62,7 @@ class AssetCheckoutController extends Controller $admin = Auth::user(); $target = $this->determineCheckoutTarget($asset); - if ($asset->is($target)) { - throw new CheckoutNotAllowed('You cannot check an asset out to itself.'); - } + $asset = $this->updateAssetLocation($asset, $target); $checkout_at = date("Y-m-d H:i:s"); diff --git a/app/Http/Requests/AssetCheckoutRequest.php b/app/Http/Requests/AssetCheckoutRequest.php index afe46440ed..4ba8ce09b7 100644 --- a/app/Http/Requests/AssetCheckoutRequest.php +++ b/app/Http/Requests/AssetCheckoutRequest.php @@ -23,7 +23,7 @@ class AssetCheckoutRequest extends Request { $rules = [ "assigned_user" => 'required_without_all:assigned_asset,assigned_location', - "assigned_asset" => 'required_without_all:assigned_user,assigned_location|different:'.$this->id, + "assigned_asset" => 'required_without_all:assigned_user,assigned_location', "assigned_location" => 'required_without_all:assigned_user,assigned_asset', "checkout_to_type" => 'required|in:asset,location,user' ]; diff --git a/app/Models/Asset.php b/app/Models/Asset.php index f0bdf4321c..2a92c81a5a 100644 --- a/app/Models/Asset.php +++ b/app/Models/Asset.php @@ -3,6 +3,7 @@ namespace App\Models; use App\Events\AssetCheckedOut; use App\Events\CheckoutableCheckedOut; +use App\Exceptions\CheckoutNotAllowed; use App\Http\Traits\UniqueSerialTrait; use App\Http\Traits\UniqueUndeletedTrait; use App\Models\Traits\Acceptable; @@ -271,6 +272,9 @@ class Asset extends Depreciable if (!$target) { return false; } + if ($this->is($target)) { + throw new CheckoutNotAllowed('You cannot check an asset out to itself.'); + } if ($expected_checkin) { $this->expected_checkin = $expected_checkin;