Skip to content

AntonMoisa/fake-car

 
 

Repository files navigation

Fake-Car

Faker provider for fake car data

Latest Stable Version Build Status Scrutinizer Code Quality Code Coverage License

Installation

composer require pelmered/fake-car

or add

"pelmered/fake-car": "^1.0"

Basic Usage

$faker = (new \Faker\Factory())::create();
$faker->addProvider(new \Faker\Provider\Fakecar($faker));


// generate matching automobile brand and model of car as a string
echo $faker->vehicle; //Volvo 740

// generate matching automobile brand and model of car as an array
echo $faker->vehicleArray; //[ 'brand' => 'Hummer', 'model' => 'H1' ]

// generate only automobile brand
echo $faker->vehicleBrand; //Ford

// generate automobile manufacturer and model of car
echo $faker->vehicleModel; //488 Spider

// generate Vehicle Identification Number(VIN) - https://en.wikipedia.org/wiki/Vehicle_identification_number
echo $faker->vin; //d0vcddxpXAcz1utgz

// generate automobile registration number
echo $faker->vehicleRegistration; //ABC-123

// generate automobile registration number with custom format
echo $faker->vehicleRegistration('[A-Z]{2}-[0-9]{5}'); //AB-12345

// generate automobile model type
echo $faker->vehicleType; //hatchback

// generate automobile fuel type
echo $faker->vehicleFuelType; //diesel

// generate automobile door count
echo $faker->vehicleDoorCount; //4

// generate automobile seat count
echo $faker->vehicleSeatCount; //5

// generate automobile properties
echo $faker->vehicleProperties; //['Towbar','Aircondition','GPS', 'Leather seats']

// generate automobile properties
echo $faker->vehicleProperties; //['Towbar','Aircondition','GPS', 'Leather seats']

// generate automobile gear type (manual or automatic)
echo $faker->vehicleGearBoxType; //manual

Laravel factory example

<?php

use Faker\Generator as Faker;

$factory->define(App\Vehicle::class, function (Faker $faker) {

    $faker->addProvider(new \Faker\Provider\Fakecar($faker));
    $v = $faker->vehicleArray();

    return [
        'vehicle_type'      => 'car',
        'vin'               => $faker->vin,
        'registration_no'   => $faker->vehicleRegistration,
        'type'              => $faker->vehicleType,
        'fuel'              => $faker->vehicleFuelType,
        'brand'             => $v['brand'],
        'model'             => $v['model'],
        'year'              => $faker->biasedNumberBetween(1998,2017, 'sqrt'),
    ];
});

About

Faker provider for fake car data

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • PHP 100.0%