['nullable', 'numeric', 'min:0'], 'retail_price' => ['nullable', 'numeric', 'min:0'], 'tax' => ['nullable', 'numeric', 'min:0', 'max:100'], ]; } public function messages(): array { return [ 'cost.numeric' => 'El costo debe ser un número.', 'cost.min' => 'El costo no puede ser negativo.', 'retail_price.numeric' => 'El precio de venta debe ser un número.', 'retail_price.min' => 'El precio de venta no puede ser negativo.', 'retail_price.gt' => 'El precio de venta debe ser mayor que el costo.', 'tax.numeric' => 'El impuesto debe ser un número.', 'tax.min' => 'El impuesto no puede ser negativo.', 'tax.max' => 'El impuesto no puede exceder el 100%.', ]; } /** * Validación condicional: retail_price > cost solo si cost > 0 */ public function withValidator($validator) { $validator->after(function ($validator) { $cost = $this->input('cost'); $retailPrice = $this->input('retail_price'); if ($cost !== null && $cost > 0 && $retailPrice !== null && $retailPrice <= $cost) { $validator->errors()->add( 'retail_price', 'El precio de venta debe ser mayor que el costo.' ); } }); } }