user()->can('edit', $this->purchase_order); } /** * Get the validation rules that apply to the request. * * @return array */ public function rules() { $rules = []; if($this->number) $rules['number'] = Rule::unique('purchase_orders')->where('company_id', auth()->user()->company()->id)->ignore($this->purchaseOrder->id); $rules['line_items'] = 'array'; $rules['discount'] = 'sometimes|numeric'; $rules['is_amount_discount'] = ['boolean']; return $rules; } protected function prepareForValidation() { $input = $this->all(); $input = $this->decodePrimaryKeys($input); $input['id'] = $this->purchase_order->id; $this->replace($input); } }