LaravelPackages.net
Acme Inc.
Toggle sidebar
mbezhanov/laravel-faker-provider-collection

A collection of custom Faker providers for your Laravel applications

72.353
21
3.2.0
About mbezhanov/laravel-faker-provider-collection

mbezhanov/laravel-faker-provider-collection is a Laravel package for a collection of custom faker providers for your laravel applications. It currently has 21 GitHub stars and 72.353 downloads on Packagist (latest version 3.2.0). Install it with composer require mbezhanov/laravel-faker-provider-collection. Discover more Laravel packages by mbezhanov or browse all Laravel packages to compare alternatives.

Last updated

laravel-faker-provider-collection

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 # 
Comments