user()->can('create', Product::class); } 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(), 'cost' => 'numeric', 'price' => 'numeric', 'quantity' => 'numeric', ]; } public function sanitize() { $input = $this->all(); if(!isset($input['quantity']) || $input['quantity'] < 1) $input['quantity'] = 1; $this->replace($input); return $this->all(); } }