Skip to main content

unit:list Command

List all available units in the database with optional filtering and locale support.

Signature​

php artisan unit:list [options]

Description​

The unit:list command displays all units stored in the database in a formatted, easy-to-read output. Units are grouped by their type and sorted by their conversion value. This command is useful for quickly viewing available units, verifying seeded data, and debugging unit-related issues.

Options​

OptionDescriptionDefault
--type=TYPEFilter units by type (e.g., weight, length, volume)All types
--locale=LOCALEDisplay translations in specified localeApp locale

Examples​

List All Units​

Display all units in the database:

php artisan unit:list

Output:

Available Units: (locale: en)

Weight:
ID: 1 Gram (g) value: 1
ID: 2 Kilogram (kg) value: 1000
ID: 3 Metric Ton (t) value: 1000000
ID: 4 Pound (lb) value: 453.592
ID: 5 Ounce (oz) value: 28.3495

Length:
ID: 6 Meter (m) value: 1
ID: 7 Centimeter (cm) value: 0.01
ID: 8 Kilometer (km) value: 1000
ID: 9 Inch (in) value: 0.0254
ID: 10 Foot (ft) value: 0.3048

Filter by Type​

Display only units of a specific type:

php artisan unit:list --type=weight

Output:

Available Units: (locale: en)

Weight:
ID: 1 Gram (g) value: 1
ID: 2 Kilogram (kg) value: 1000
ID: 3 Metric Ton (t) value: 1000000
ID: 4 Pound (lb) value: 453.592
ID: 5 Ounce (oz) value: 28.3495

Display in Different Locale​

Show unit names in a specific language:

php artisan unit:list --locale=fa

Output:

Available Units: (locale: fa)

Weight:
ID: 1 گرم (g) value: 1
ID: 2 کیلوگرم (kg) value: 1000
ID: 3 تن (t) value: 1000000
ID: 4 پوند (lb) value: 453.592

Combine Options​

Filter by type and display in specific locale:

php artisan unit:list --type=length --locale=en

Error Handling​

Invalid Type​

If an invalid unit type is provided:

php artisan unit:list --type=invalid

Output:

Error: Invalid unit type: invalid. Available types: weight, length, currency, volume, ...

No Units Found​

If no units exist in the database:

php artisan unit:list

Output:

Warning: No units found.

Available Unit Types​

The following types can be used with the --type option:

TypeDescription
weightWeight units (gram, kilogram, etc.)
lengthLength units (meter, centimeter, etc.)
currencyCurrency units (USD, EUR, etc.)
volumeVolume units (liter, milliliter, etc.)
temperatureTemperature units (Celsius, Fahrenheit, etc.)
areaArea units (square meter, hectare, etc.)
pressurePressure units (Pascal, bar, etc.)
speedSpeed units (m/s, km/h, etc.)
timeTime units (second, minute, etc.)
energyEnergy units (Joule, calorie, etc.)
powerPower units (Watt, kilowatt, etc.)
data_storageData storage units (Byte, KB, MB, etc.)
data_transferData transfer units (bps, Mbps, etc.)
...And 20+ more types

Use Cases​

Development Debugging​

Quickly check if units were seeded correctly:

php artisan unit:list --type=weight

Finding Unit IDs​

Find the ID of a specific unit for use in code:

php artisan unit:list --type=currency | grep USD

Verifying Translations​

Check if translations exist for a specific locale:

php artisan unit:list --locale=fa

Documentation Generation​

Export unit list for documentation purposes:

php artisan unit:list > units.txt