Skip to main content

unit:seed Command

Seed default units into the database with an interactive selection menu.

Signature

php artisan unit:seed

Description

The unit:seed command provides an interactive interface to seed default units into your database. It presents a multi-select menu where you can choose which unit types to seed. Each unit type includes a comprehensive set of commonly used units with translations for supported locales.

Interactive Menu

When you run the command, you'll see an interactive selection menu:

┌ Select unit types to seed ──────────────────────────────────────┐
│ › ◉ Weight (وزن) │
│ ◉ Length (طول) │
│ ◯ Currency (ارز) │
│ ◯ Number (تعداد) │
│ ◉ Volume (حجم) │
│ ◯ Temperature (دما) │
│ ◯ Area (مساحت) │
│ ◯ Pressure (فشار) │
│ ◯ Speed (سرعت) │
│ ... (30+ types) │
└─────────────────────────────────────────────────────────────────┘

Use arrow keys to navigate, space to select/deselect, and enter to confirm.

Available Unit Types

The seeder supports all 30+ unit types:

Physical Units

TypeLabelExample Units
weightWeight (وزن)Gram, Kilogram, Ton, Pound, Ounce
lengthLength (طول)Meter, Centimeter, Kilometer, Inch, Foot, Mile
volumeVolume (حجم)Liter, Milliliter, Gallon, Quart, Pint
areaArea (مساحت)Square Meter, Hectare, Acre, Square Foot
temperatureTemperature (دما)Celsius, Fahrenheit, Kelvin
pressurePressure (فشار)Pascal, Bar, PSI, Atmosphere
speedSpeed (سرعت)m/s, km/h, mph, Knot
forceForce (نیرو)Newton, Kilonewton, Pound-force
timeTime (زمان)Second, Minute, Hour, Day, Week
angleAngle (زاویه)Degree, Radian, Gradian

Energy & Power Units

TypeLabelExample Units
energyEnergy (انرژی)Joule, Calorie, kWh, BTU
powerPower (توان)Watt, Kilowatt, Horsepower
torqueTorque (گشتاور)Newton-meter, Pound-foot
frequencyFrequency (بسامد)Hertz, kHz, MHz, GHz
accelerationAcceleration (شتاب)m/s², G-force

Electrical Units

TypeLabelExample Units
electric_currentElectric Current (جریان الکتریکی)Ampere, Milliampere
electric_voltageElectric Voltage (ولتاژ)Volt, Millivolt, Kilovolt
electric_resistanceElectric Resistance (مقاومت)Ohm, Kiloohm, Megaohm
electric_capacitanceElectric Capacitance (خازن)Farad, Microfarad, Picofarad
electric_inductanceElectric Inductance (القا)Henry, Millihenry
magnetic_fluxMagnetic Flux (شار مغناطیسی)Weber, Tesla

Scientific Units

TypeLabelExample Units
densityDensity (چگالی)kg/m³, g/cm³, lb/ft³
viscosityViscosity (ویسکوزیته)Pascal-second, Poise
concentrationConcentration (غلظت)mol/L, ppm, percent
radiationRadiation (تابش)Becquerel, Sievert, Gray
luminosityLuminosity (روشنایی)Lumen, Candela, Lux
heat_transfer_coefficientHeat Transfer (ضریب انتقال حرارت)W/(m²·K)

Digital Units

TypeLabelExample Units
data_storageData Storage (ذخیره‌سازی داده)Byte, KB, MB, GB, TB, PB
data_transferData Transfer (انتقال داده)bps, Kbps, Mbps, Gbps

Flow Units

TypeLabelExample Units
mass_flowMass Flow (جریان جرمی)kg/s, lb/h, t/h
volumetric_flowVolumetric Flow (جریان حجمی)L/s, m³/h, gal/min

Other Units

TypeLabelExample Units
currencyCurrency (ارز)USD, EUR, GBP, IRR
numberNumber (تعداد)Piece, Dozen, Gross
cookingCooking (پخت و پز)Cup, Tablespoon, Teaspoon
fuel_consumptionFuel Consumption (مصرف سوخت)L/100km, mpg, km/L
cryptoCryptocurrency (رمزارز)Bitcoin, Ethereum, Satoshi

Output

After selecting types and confirming, the command shows progress:

Seeding Weight units...
✓ Gram created
✓ Kilogram created
✓ Milligram created
✓ Metric Ton created
✓ Pound created
✓ Ounce created

Seeding Length units...
✓ Meter created
✓ Centimeter created
✓ Millimeter created
✓ Kilometer created
✓ Inch created
✓ Foot created
✓ Yard created
✓ Mile created

Seeding Volume units...
✓ Liter created
✓ Milliliter created
✓ Cubic Meter created
✓ Gallon created

All selected unit types have been seeded successfully!

Base Unit Handling

Each seeder automatically creates the base unit first (with value = 1), then creates other units relative to it:

Weight:
├── Gram (base unit, value = 1)
├── Kilogram (value = 1000)
├── Milligram (value = 0.001)
├── Metric Ton (value = 1000000)
├── Pound (value = 453.592)
└── Ounce (value = 28.3495)

Translations

Each seeded unit includes translations for supported locales:

// Example: Kilogram unit
[
'en' => [
'name' => 'Kilogram',
'code' => 'kg',
'position' => 'right',
],
'fa' => [
'name' => 'کیلوگرم',
'code' => 'کیلو',
'position' => 'right',
],
]

Non-Interactive Mode

For CI/CD pipelines or automated scripts, you may need to seed all units without interaction. This can be done by calling the seeder classes directly:

// In a seeder or command
use JobMetric\UnitConverter\Database\Seeders\WeightUnitSeeder;
use JobMetric\UnitConverter\Database\Seeders\LengthUnitSeeder;

(new WeightUnitSeeder())->run();
(new LengthUnitSeeder())->run();

Or create a custom seeder that calls multiple seeders:

namespace Database\Seeders;

use Illuminate\Database\Seeder;

class UnitSeeder extends Seeder
{
public function run(): void
{
$this->call([
\JobMetric\UnitConverter\Database\Seeders\WeightUnitSeeder::class,
\JobMetric\UnitConverter\Database\Seeders\LengthUnitSeeder::class,
\JobMetric\UnitConverter\Database\Seeders\VolumeUnitSeeder::class,
// Add more as needed
]);
}
}

Then run:

php artisan db:seed --class=UnitSeeder

Re-running the Seeder

If units already exist, the seeder will skip them to avoid duplicates. To re-seed:

  1. Delete existing units first:

    use JobMetric\UnitConverter\Models\Unit;
    Unit::where('type', 'weight')->delete();
  2. Run the seeder again:

    php artisan unit:seed

Use Cases

Initial Setup

Seed common units when setting up a new project:

php artisan migrate
php artisan unit:seed
# Select: weight, length, volume, currency

Adding New Unit Types

Add units for new features:

php artisan unit:seed
# Select: temperature, pressure (for a new scientific module)

Development Environment

Seed all units for development:

php artisan unit:seed
# Select all types