Weave Code
Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Faker Laravel Package

mubiridziri/faker

A lightweight fake-data generator for Laravel and PHP that quickly produces realistic names, emails, addresses, phone numbers, and more. Simple to install and easy to extend with custom providers, it's ideal for tests, seeders, demos, and populating databases during development.

View on GitHub
Deep Wiki
Context7

Getting Started

  • Install with Composer (composer require <vendor>/<package>) — the service provider is auto-discovered in Laravel.
  • First place to look: the package’s README and src/ directory for available generators. In 1.2, the new RandomPhoneNumber and RandomDateTimeThisMonth classes are the quickest wins.
  • Minimal first use case: replace hard-coded dummy values in a model factory. For example, a UserFactory can use RandomPhoneNumber for the phone field and RandomDateTimeThisMonth for created_at or a monthly subscription date, giving realistic, varied test data without extra setup.

Implementation Patterns

  • Factories & seeders – Call the generators directly inside factory definitions or seeders. If the classes expose a static generate() method, use 'phone' => RandomPhoneNumber::generate(); otherwise instantiate and invoke. For bulk seeding, loop over the generator to produce many records.
  • Time-sensitive features – Use RandomDateTimeThisMonth when testing monthly reports, billing cycles, or “this month” filters. It guarantees dates fall inside the current calendar month, avoiding flaky tests that break when run at month boundaries.
  • Combining with Faker – The package can complement Faker. If you need locale-specific phone formats, keep Faker’s phoneNumber() for those cases and use RandomPhoneNumber for generic or quick stubs.
  • Dependency injection – If the package binds generators in the container, resolve them via constructor injection in services or test helpers to keep code testable and swappable.
  • Deterministic tests – If the package supports seeding (many random-data libraries do), call the seed method in setUp() to make generated values reproducible across test runs.

Gotchas and Tips

  • Phone number validity – RandomPhoneNumber may produce generic or non-locale-aware numbers. For validation-heavy tests (e.g., phone:US), fall back to Faker’s locale-specific provider or wrap the output with a formatter.
  • Timezone awareness – RandomDateTimeThisMonth relies on the current date. Ensure config('app.timezone') is set correctly in your test environment; otherwise “this month” may shift unexpectedly when comparing against UTC-stored timestamps.
  • Month boundaries – The generator should handle short months and leap years, but if you see odd dates near month-end, pin the system clock using Laravel’s travelTo() or Carbon’s setTestNow() before generating.
  • Class name collisions – Faker already has phoneNumber and dateTimeThisMonth formatters. Avoid importing both without aliases, and prefer the package’s classes only where you need standalone generation outside a Faker instance.
  • Extension points – Check whether the package allows custom generators via config or container binding. If you need a specific phone format, you may be able to extend or override the default class rather than forking.
  • Upgrading from 1.1 – Release 1.2 is additive (two new classes), so no breaking changes are expected. Run composer update and verify your factories still pass; add the new generators incrementally where they replace ad-hoc rand() or Carbon calls.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
3mdikram/worldmoneywords
snowsoft/config
itmosoft/laravel-subscriptions
larva/laravel-ai-qwen
diephp/sequences
users-au/socialite-provider
twidpay/twid-logger
mrnewport/laravel-plaid
mrnewport/laravel-repo
mrnewport/laravel-docsign
mrnewport/laravel-stow
mrnewport/laravel-flow
mrnewport/laravel-priceable
mrnewport/laravel-nestedterms
fredmeng/laravel-apidoc-generator
itstructure/laravel-multilingual-tools
pdustdar/elasticsearch
markupai/php-sdk
rlacerda83/lumem-microservice-shipment
uni-method/symfony-lib