Skip to main content

Unit Types

Laravel Unit Converter supports over 30 unit types, each representing an isolated conversion family. Units can only be converted within their own type.

Namespace​

JobMetric\UnitConverter\Enums\UnitTypeEnum

Overview​

The UnitTypeEnum enum defines all supported unit types:

use JobMetric\UnitConverter\Enums\UnitTypeEnum;

// Get all values
$types = UnitTypeEnum::values();

// Use specific type
$weightType = UnitTypeEnum::WEIGHT;
echo $weightType->value; // 'weight'
echo $weightType->label(); // Translated label

Physical Units​

Weight​

UnitTypeEnum::WEIGHT // 'weight'

Units for measuring mass: gram, kilogram, ton, pound, ounce, etc.

Common units:

UnitCodeValue (relative to gram)
Gramg1
Kilogramkg1000
Milligrammg0.001
Metric Tont1000000
Poundlb453.592
Ounceoz28.3495

Length​

UnitTypeEnum::LENGTH // 'length'

Units for measuring distance: meter, centimeter, kilometer, inch, foot, etc.

Common units:

UnitCodeValue (relative to meter)
Meterm1
Centimetercm0.01
Millimetermm0.001
Kilometerkm1000
Inchin0.0254
Footft0.3048
Yardyd0.9144
Milemi1609.344

Volume​

UnitTypeEnum::VOLUME // 'volume'

Units for measuring capacity: liter, milliliter, gallon, quart, etc.

Common units:

UnitCodeValue (relative to liter)
LiterL1
MillilitermL0.001
Cubic meterm³1000
Gallon (US)gal3.78541
Quartqt0.946353
Pintpt0.473176
Fluid ouncefl oz0.0295735

Area​

UnitTypeEnum::AREA // 'area'

Units for measuring surface area: square meter, hectare, acre, etc.

Common units:

UnitCodeValue (relative to m²)
Square meterm²1
Square centimetercm²0.0001
Square kilometerkm²1000000
Hectareha10000
Acreac4046.86
Square footft²0.092903
Square inchin²0.00064516

Temperature​

UnitTypeEnum::TEMPERATURE // 'temperature'

Units for measuring temperature: Celsius, Fahrenheit, Kelvin.

Note: Temperature conversions require special handling due to non-linear relationships. The base unit approach works for relative differences but not absolute conversions.

Common units:

UnitCodeNotes
Celsius°CBase unit
Fahrenheit°F°F = °C × 9/5 + 32
KelvinKK = °C + 273.15

Pressure​

UnitTypeEnum::PRESSURE // 'pressure'

Units for measuring force per area: Pascal, bar, psi, atmosphere, etc.

Common units:

UnitCodeValue (relative to Pascal)
PascalPa1
KilopascalkPa1000
Barbar100000
Atmosphereatm101325
PSIpsi6894.76
mmHgmmHg133.322

Speed​

UnitTypeEnum::SPEED // 'speed'

Units for measuring velocity: meters/second, km/h, mph, knots, etc.

Common units:

UnitCodeValue (relative to m/s)
Meter/secondm/s1
Kilometer/hourkm/h0.277778
Mile/hourmph0.44704
Knotkn0.514444
Foot/secondft/s0.3048

Force​

UnitTypeEnum::FORCE // 'force'

Units for measuring force: Newton, kilonewton, pound-force, etc.

Common units:

UnitCodeValue (relative to Newton)
NewtonN1
KilonewtonkN1000
Pound-forcelbf4.44822
Dynedyn0.00001
Kilogram-forcekgf9.80665

Time​

UnitTypeEnum::TIME // 'time'

Units for measuring duration: second, minute, hour, day, etc.

Common units:

UnitCodeValue (relative to second)
Seconds1
Millisecondms0.001
Minutemin60
Hourh3600
Dayd86400
Weekwk604800
Yearyr31536000

Angle​

UnitTypeEnum::ANGLE // 'angle'

Units for measuring angles: degree, radian, gradian, etc.

Common units:

UnitCodeValue (relative to degree)
Degree°1
Radianrad57.2958
Gradiangrad0.9
Arcminute'0.0166667
Arcsecond"0.000277778

Energy & Power​

Energy​

UnitTypeEnum::ENERGY // 'energy'

Units for measuring energy: Joule, calorie, kilowatt-hour, BTU, etc.

Common units:

UnitCodeValue (relative to Joule)
JouleJ1
KilojoulekJ1000
Caloriecal4.184
Kilocaloriekcal4184
Watt-hourWh3600
Kilowatt-hourkWh3600000
BTUBTU1055.06

Power​

UnitTypeEnum::POWER // 'power'

Units for measuring power: Watt, kilowatt, horsepower, etc.

Common units:

UnitCodeValue (relative to Watt)
WattW1
KilowattkW1000
MegawattMW1000000
Horsepowerhp745.7
BTU/hourBTU/h0.293071

Torque​

UnitTypeEnum::TORQUE // 'torque'

Units for measuring rotational force: Newton-meter, pound-foot, etc.

Common units:

UnitCodeValue (relative to N·m)
Newton-meterN·m1
Kilonewton-meterkN·m1000
Pound-footlb·ft1.35582
Pound-inchlb·in0.112985

Frequency​

UnitTypeEnum::FREQUENCY // 'frequency'

Units for measuring frequency: Hertz, kilohertz, megahertz, etc.

Common units:

UnitCodeValue (relative to Hz)
HertzHz1
KilohertzkHz1000
MegahertzMHz1000000
GigahertzGHz1000000000
RPMrpm0.0166667

Acceleration​

UnitTypeEnum::ACCELERATION // 'acceleration'

Units for measuring acceleration: m/s², g-force, etc.

Common units:

UnitCodeValue (relative to m/s²)
Meter/s²m/s²1
G-forceg9.80665
Foot/s²ft/s²0.3048
GalGal0.01

Electrical Units​

Electric Current​

UnitTypeEnum::ELECTRIC_CURRENT // 'electric_current'

Units for measuring current: Ampere, milliampere, microampere.

Electric Voltage​

UnitTypeEnum::ELECTRIC_VOLTAGE // 'electric_voltage'

Units for measuring voltage: Volt, millivolt, kilovolt.

Electric Resistance​

UnitTypeEnum::ELECTRIC_RESISTANCE // 'electric_resistance'

Units for measuring resistance: Ohm, kiloohm, megaohm.

Electric Capacitance​

UnitTypeEnum::ELECTRIC_CAPACITANCE // 'electric_capacitance'

Units for measuring capacitance: Farad, microfarad, picofarad.

Electric Inductance​

UnitTypeEnum::ELECTRIC_INDUCTANCE // 'electric_inductance'

Units for measuring inductance: Henry, millihenry, microhenry.

Magnetic Flux​

UnitTypeEnum::MAGNETIC_FLUX // 'magnetic_flux'

Units for measuring magnetic flux: Weber, Tesla, Gauss.

Scientific Units​

Density​

UnitTypeEnum::DENSITY // 'density'

Units for measuring density: kg/m³, g/cm³, lb/ft³.

Viscosity​

UnitTypeEnum::VISCOSITY // 'viscosity'

Units for measuring viscosity: Pascal-second, Poise, Stokes.

Concentration​

UnitTypeEnum::CONCENTRATION // 'concentration'

Units for measuring concentration: mol/L, ppm, percent.

Radiation​

UnitTypeEnum::RADIATION // 'radiation'

Units for measuring radiation: Becquerel, Sievert, Gray.

Luminosity​

UnitTypeEnum::LUMINOSITY // 'luminosity'

Units for measuring light: Lumen, Candela, Lux.

Heat Transfer Coefficient​

UnitTypeEnum::HEAT_TRANSFER_COEFFICIENT // 'heat_transfer_coefficient'

Units for measuring heat transfer: W/(m²·K), BTU/(h·ft²·°F).

Flow Units​

Mass Flow​

UnitTypeEnum::MASS_FLOW // 'mass_flow'

Units for measuring mass flow rate: kg/s, lb/h, t/h.

Volumetric Flow​

UnitTypeEnum::VOLUMETRIC_FLOW // 'volumetric_flow'

Units for measuring volume flow rate: L/s, m³/h, gal/min.

Digital Units​

Data Storage​

UnitTypeEnum::DATA_STORAGE // 'data_storage'

Units for measuring digital storage: Byte, KB, MB, GB, TB, PB.

Common units:

UnitCodeValue (relative to Byte)
ByteB1
KilobyteKB1024
MegabyteMB1048576
GigabyteGB1073741824
TerabyteTB1099511627776
PetabytePB1125899906842624

Data Transfer​

UnitTypeEnum::DATA_TRANSFER // 'data_transfer'

Units for measuring data transfer rate: bps, Kbps, Mbps, Gbps.

Common units:

UnitCodeValue (relative to bps)
Bit/secondbps1
Kilobit/sKbps1000
Megabit/sMbps1000000
Gigabit/sGbps1000000000
Byte/secondB/s8
Megabyte/sMB/s8000000

Financial Units​

Currency​

UnitTypeEnum::CURRENCY // 'currency'

Units for representing currencies with exchange rates.

Example setup:

CurrencyCodeValue (relative to base)
US DollarUSD1 (base)
EuroEUR0.92
British PoundGBP0.79
Japanese YenJPY149.5

Cryptocurrency​

UnitTypeEnum::CRYPTO // 'crypto'

Units for representing cryptocurrencies.

Example units:

  • Bitcoin (BTC)
  • Ethereum (ETH)
  • Satoshi (sat)

Number​

UnitTypeEnum::NUMBER // 'number'

Units for counting: pieces, dozen, gross, etc.

Cooking Units​

UnitTypeEnum::COOKING // 'cooking'

Units for cooking measurements: cup, tablespoon, teaspoon, etc.

Common units:

UnitCodeValue (relative to mL)
MillilitermL1
Teaspoontsp5
Tablespoontbsp15
Cup (US)cup240
Fluid ouncefl oz30
Pintpt480

Fuel Consumption​

UnitTypeEnum::FUEL_CONSUMPTION // 'fuel_consumption'

Units for measuring fuel efficiency: L/100km, mpg, km/L.

Using Unit Types​

In Model Configuration​

use JobMetric\UnitConverter\HasUnit;
use JobMetric\UnitConverter\Enums\UnitTypeEnum;

class Product extends Model
{
use HasUnit;

protected array $unitables = [
'weight' => UnitTypeEnum::WEIGHT,
'length' => UnitTypeEnum::LENGTH,
'price' => UnitTypeEnum::CURRENCY,
];
}

In Unit Creation​

use JobMetric\UnitConverter\Facades\UnitConverter;
use JobMetric\UnitConverter\Enums\UnitTypeEnum;

UnitConverter::store([
'type' => UnitTypeEnum::WEIGHT->value, // or just 'weight'
'value' => 1000,
'translation' => [...],
]);

Getting Available Types​

use JobMetric\UnitConverter\Enums\UnitTypeEnum;

// Get all type values
$types = UnitTypeEnum::values();
// => ['weight', 'length', 'currency', ...]

// Get all cases
$cases = UnitTypeEnum::cases();

// Get translated label
$label = UnitTypeEnum::WEIGHT->label();
// => 'Weight' (translated)

Seeding Units​

Use the unit:seed command to seed default units:

php artisan unit:seed

This presents an interactive menu to select which unit types to seed. Each seeder creates common units for that type with multilingual translations.