Code Monkey home page Code Monkey logo

fake-car's Introduction

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'),
        ];
    }
}

fake-car's People

Contributors

aalaap avatar agasigp avatar nickedwards avatar ohori avatar pelmered avatar scrutinizer-auto-fixer avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.