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