Force at least 1 product quantity

This commit is contained in:
David Bomba 2019-10-04 21:57:33 +10:00
parent 1f1ffd3240
commit 2c25f20a25
2 changed files with 26 additions and 0 deletions

View File

@ -29,6 +29,8 @@ class StoreProductRequest extends Request
public function rules()
{
$this->sanitize();
return [
'product_key' => 'required|unique:products,product_key,null,null,company_id,'.auth()->user()->companyId(),
'cost' => 'numeric',
@ -37,5 +39,16 @@ class StoreProductRequest extends Request
];
}
public function sanitize()
{
$input = $this->all();
if($input['quantity'] < 1)
$input['quantity'] = 1;
$this->replace($input);
return $this->all();
}
}

View File

@ -33,6 +33,7 @@ class UpdateProductRequest extends Request
public function rules()
{
//when updating you need to ignore the column ID
$this->sanitize();
return [
//'product_key' => 'unique:products,product_key,'.$this->product->id.',id,company_id,'.auth()->user()->companyId(),
@ -42,5 +43,17 @@ class UpdateProductRequest extends Request
];
}
public function sanitize()
{
$input = $this->all();
if($input['quantity'] < 1)
$input['quantity'] = 1;
$this->replace($input);
return $this->all();
}
}