mirror of
https://github.com/snipe/snipe-it.git
synced 2024-12-24 05:04:07 -08:00
Add comment and improve method
This commit is contained in:
parent
4295bad12f
commit
1d5b48b88d
|
@ -47,14 +47,17 @@ class StoreAssetRequest extends ImageUploadRequest
|
||||||
{
|
{
|
||||||
$modelRules = (new Asset)->getRules();
|
$modelRules = (new Asset)->getRules();
|
||||||
|
|
||||||
$modelRules['purchase_cost'] = $this->removeNumericRulesFromPurchaseCost($modelRules['purchase_cost']);
|
// If purchase_cost was submitted as a string with a comma separator
|
||||||
|
// then we need to ignore the normal numeric rules.
|
||||||
|
// Since the original rules still live on the model they will be run
|
||||||
|
// right before saving (and after purchase_cost has been
|
||||||
|
// converted to a float via setPurchaseCostAttribute).
|
||||||
|
$modelRules = $this->removeNumericRulesFromPurchaseCost($modelRules);
|
||||||
|
|
||||||
$rules = array_merge(
|
return array_merge(
|
||||||
$modelRules,
|
$modelRules,
|
||||||
parent::rules(),
|
parent::rules(),
|
||||||
);
|
);
|
||||||
|
|
||||||
return $rules;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private function parseLastAuditDate(): void
|
private function parseLastAuditDate(): void
|
||||||
|
@ -74,15 +77,19 @@ class StoreAssetRequest extends ImageUploadRequest
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private function removeNumericRulesFromPurchaseCost($purchaseCost)
|
private function removeNumericRulesFromPurchaseCost(array $rules): array
|
||||||
{
|
{
|
||||||
|
$purchaseCost = $rules['purchase_cost'];
|
||||||
|
|
||||||
// If rule is in "|" format then turn it into an array
|
// If rule is in "|" format then turn it into an array
|
||||||
if (is_string($purchaseCost)) {
|
if (is_string($purchaseCost)) {
|
||||||
$purchaseCost = explode('|', $purchaseCost);
|
$purchaseCost = explode('|', $purchaseCost);
|
||||||
}
|
}
|
||||||
|
|
||||||
return array_filter($purchaseCost, function ($rule) {
|
$rules['purchase_cost'] = array_filter($purchaseCost, function ($rule) {
|
||||||
return $rule !== 'numeric' && $rule !== 'gte:0';
|
return $rule !== 'numeric' && $rule !== 'gte:0';
|
||||||
});
|
});
|
||||||
|
|
||||||
|
return $rules;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue