• Stars
    star
    116
  • Rank 302,923 (Top 6 %)
  • Language
    PHP
  • License
    MIT License
  • Created over 6 years ago
  • Updated 10 days ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Faker provider for fake car data

Fake-Car

Faker provider for fake car data

Build Status Monthly Downloads Latest Stable Version Latest Unstable Version Scrutinizer Code Quality Code Coverage License

Installation

To install as a dev dependency run:

composer require pelmered/fake-car --dev

Remove the --dev flag if you need it in production.

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 gear type (manual or automatic)
echo $faker->vehicleGearBoxType; //manual

Laravel factory example

<?php
namespace Database\Factories;

use App\Models\Vehicle;
use Faker\Provider\Fakecar;
use Illuminate\Database\Eloquent\Factories\Factory;

class VehicleFactory extends Factory
{
    /**
     * The name of the factory's corresponding model.
     *
     * @var string
     */
    protected $model = Vehicle::class;

    /**
     * Define the model's default state.
     *
     * @return array
     */
    public function definition()
    {
        $this->faker->addProvider(new Fakecar($this->faker));
        $vehicle = $this->faker->vehicleArray();

        return [
            'vehicle_type'    => 'car',
            'vin'             => $this->faker->vin,
            'registration_no' => $this->faker->vehicleRegistration,
            'chassis_type'    => str_replace(' ', '_', $this->faker->vehicleType),
            'fuel'            => $this->faker->vehicleFuelType,
            'brand'           => $vehicle['brand'],
            'model'           => $vehicle['model'],
            'year'            => $this->faker->biasedNumberBetween(1990, date('Y'), 'sqrt'),
        ];
    }
}