Skip to content
Faker provider for fake car data
PHP
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
src
tests/Faker
.gitignore
.scrutinizer.yml
.travis.yml
LICENSE
README.md
composer.json
phpcs.xml
phpunit.xml.dist

README.md

Fake-Car

Faker provider for fake car data

Latest Stable Version Build Status Scrutinizer Code Quality Code Coverage License Build Status

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'),
    ];
});
You can’t perform that action at this time.