mbezhanov / laravel-faker-provider-collection
A collection of custom Faker providers for your Laravel applications
Installs: 62 682
Dependents: 1
Suggesters: 0
Security: 0
Stars: 18
Watchers: 3
Forks: 6
Open Issues: 0
Requires
- php: ^8.1
- illuminate/support: ^10.0|^11.0
- mbezhanov/faker-provider-collection: ^2.0
README
This package contains a Service Provider that automatically registers the faker-provider-collection library with your Laravel application.
Detailed information about the various Faker providers exposed by faker-provider-collection can be found here.
Quickstart
Add the provider to your Laravel project with Composer:
composer require --dev mbezhanov/laravel-faker-provider-collection
Add the FakerServiceProvider
class to your ./bootstrap/providers.php
file:
return [ // other provider definitions Bezhanov\Faker\Laravel\FakerServiceProvider::class, ];
At this point, you should be able to use the all the additional faker providers bundled with the library in your Model Factories
In example, assuming you have defined the following model factory:
<?php namespace Database\Factories; use Illuminate\Database\Eloquent\Factories\Factory; class StudentFactory extends Factory { /** * Define the model's default state. * * @return array<string, mixed> */ public function definition(): array { return [ 'university' => fake()->university, 'sport' => fake()->sport, 'team' => fake()->team, ]; } }
You should be able to do:
/app # php artisan tinker Psy Shell v0.12.2 (PHP 8.3.4 — cli) by Justin Hileman > \App\Student::factory(5)->make(); = Illuminate\Database\Eloquent\Collection {#6008 all: [ App\Models\Student {#6065 university: "Ironston Technical College", sport: "baseball", team: "Minnesota Warlocks", }, App\Models\Student {#5980 university: "Mallowpond TAFE", sport: "hockey", team: "New York Oracles", }, App\Models\Student {#6066 university: "Vertapple College", sport: "rugby", team: "Delaware Bees", }, App\Models\Student {#6069 university: "Falconholt University", sport: "lacrosse", team: "West Virginia Vixens", }, App\Models\Student {#6046 university: "Flowerlake College", sport: "basketball", team: "Louisiana Spiders", }, ], } > exit INFO Goodbye. /app #