'required|numeric|min:0.01|max:99999999.99', ]; if (! $this->isUpdate()) { $rules['product_id'] = 'required|integer|exists:product,id'; } return $rules; } public function messages(): array { return [ 'product_id.required' => '请选择商品', 'product_id.integer' => '商品参数错误', 'product_id.exists' => '商品不存在', 'quantity.required' => '订货数量不能为空', 'quantity.numeric' => '订货数量必须为数字', 'quantity.min' => '订货数量必须大于 0', 'quantity.max' => '订货数量超出上限', ]; } }