spatie/unit-conversions
Lightweight PHP unit conversion library by Spatie. Currently supports weight conversion from kilograms to pounds via a fluent API: Weight::fromKilograms(100)->toLbs(). Install with Composer and extend as more units are added.
kg ↔ lbs), making it a point solution rather than a general-purpose tool. Ideal for applications requiring weight conversions (e.g., e-commerce, logistics, fitness apps).fromKilograms()->toLbs()) simplifies integration. Can be wrapped in a service class or facade for consistency.php-math/units) be more maintainable?UnitConversionService class.0 kg, NaN inputs).// app/Services/UnitConverter.php
class UnitConverter {
public static function convertWeight(float $kg): float {
return Weight::fromKilograms($kg)->toLbs();
}
}
$this->app->bind(UnitConverter::class, function ($app) {
return new UnitConverter();
});
DECIMAL(10,4) for lbs).$cacheKey = "weight_{$kg}_to_lbs";
return Cache::remember($cacheKey, now()->addHours(1), function () use ($kg) {
return Weight::fromKilograms($kg)->toLbs();
});
round($result, 2)).How can I help you explore Laravel packages today?