1. Go to this page and download the library: Download pelmered/fake-car library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
pelmered / fake-car example snippets
$faker = (new \Faker\Factory())::create();
$faker->addProvider(new \Faker\Provider\FakeCar($faker));
// generate matching automobile brand and model of a car as a string
echo $faker->vehicle(); // 'Volvo 740'
// generate matching automobile brand and model of a 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'
echo $faker->vehicleFuelType(2); // ['diesel', 'gasoline']
// 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
// generate automobile engine power
echo $faker->vehicleEnginePower(); // '250 hp'
// generate automobile engine power without a unit
echo $faker->vehicleEnginePowerValue(); // 175
// generate automobile engine torque
echo $faker->vehicleEngineTorque(); // '300 nm'
// generate automobile engine power without a unit
echo $faker->vehicleEngineTorqueValue(); // 450
// generate automobile engine displacement
echo $faker->vehicleEngineDisplacement(); // '2.0 l'
// generate automobile engine displacement without unit
echo $faker->vehicleEngineDisplacementValue(); // 2.0
// generate automobile engine fuel consumption
echo $faker->vehicleFuelConsumption(); // '5.0 l/100km'
// generate automobile engine fuel consumption without unit
echo $faker->vehicleFuelConsumptionValue(); // 5.0
// generate automobile engine fuel consumption without unit
echo $faker->vehicleEngineCylinders(); // 4
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'),
];
}
}
$fakeCarDataProvider = new \Faker\Provider\FakeCarDataProvider(new BMWFakeCarData);
$faker = (new \Faker\Factory())::create();
$fakeCar = new \Faker\Provider\FakeCar($faker);
$fakeCar->setDataProvider($fakeCarDataProvider);
$faker->addProvider($fakeCar);
echo $faker->vehicleBrand; // BMW
namespace FakeCar\Tests\TestProviders;
use Faker\Provider\FakeCarDataProviderInterface;
use Faker\Provider\FakeCarHelper;
class FerrariEnzoTestProvider implements FakeCarDataProviderInterface
{
public function getVehicleBrand(): string
{
return 'Ferrari';
}
public function getVehicleModel(): string
{
return 'Enzo';
}
public function getBrandsWithModels(): array
{
return [
'brand' => $this->getVehicleBrand(),
'model' => $this->getVehicleModel(),
];
}
public function getVehicleType(): string
{
return 'coupe';
}
public function getVehicleFuelType(): string|array
{
return 'gasoline';
}
public function getVehicleDoorCount(): int
{
return 2;
}
public function getVehicleSeatCount(): int
{
return 2;
}
public function getVehicleProperties(int $count = 0): array
{
return [
'Air condition',
'GPS',
'Leather seats',
];
}
public function getVehicleGearBoxType(): string
{
return FakeCarHelper::getWeighted([
'manual' => 70,
'automatic' => 30,
]);
}
}
$fakeCarDataProvider = new FerrariEnzoTestProvider();
$faker = (new \Faker\Factory())::create();
$fakeCar = new \Faker\Provider\FakeCar($faker);
$fakeCar->setDataProvider($fakeCarDataProvider);
$faker->addProvider($fakeCar);
echo $faker->vehicleBrand; // Ferrari
echo $faker->vehicleModel; // Enzo
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.