PHPackages                             guidocella/eloquent-populator - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Database &amp; ORM](/categories/database)
4. /
5. guidocella/eloquent-populator

ActiveLibrary[Database &amp; ORM](/categories/database)

guidocella/eloquent-populator
=============================

Guess attributes for Eloquent model factories

v3.0.7(3mo ago)7762.7k↓73.1%92MITPHP

Since Dec 16Pushed 3mo ago5 watchersCompare

[ Source](https://github.com/guidocella/eloquent-populator)[ Packagist](https://packagist.org/packages/guidocella/eloquent-populator)[ RSS](/packages/guidocella-eloquent-populator/feed)WikiDiscussions master Synced 2d ago

READMEChangelog (10)Dependencies (10)Versions (30)Used By (2)

Eloquent Populator
==================

[](#eloquent-populator)

This package provides default attributes for Laravel model factories by guessing the best [Faker](https://github.com/fakerphp/Faker) formatters from columns' names and types. For example, if a column is called `first_name`, it will use `$faker->firstName()`. If unable to guess by the column's name, it will guess the formatter by the column's type; for example, it will use `$faker->text()` for a `VARCHAR` column, or a Carbon instance for a `TIMESTAMP`. Models of `BelongsTo` relationships that have been defined are created as well. Furthermore, if you use the [Multilingual](https://github.com/guidocella/laravel-multilingual) package, for translatable attributes Populator will generate arrays with a different value for each configured locale.

Compared to packages that generate factories once, you generally don't have to update your factories as you change their table definitions and they will be very small.

Installation
------------

[](#installation)

Install the package with Composer:

```
composer require --dev guidocella/eloquent-populator
```

Model factory integration
-------------------------

[](#model-factory-integration)

Call `Populator::guessFormatters($this->modelName())` in your factories' `definition` methods to get an array with the guessed formatters. You may merge these with custom attributes whose guessed formatter isn't accurate.

```
use GuidoCella\EloquentPopulator\Populator;

...

public function definition(): array
{
    return [...Populator::guessFormatters($this->modelName()), ...[
        'avatar' => $this->faker->imageUrl()
    ]];
}
```

If you execute `php artisan stub:publish`, you can include the call to Populator in `factory.stub` so that `php artisan make:factory` will add it.

After guessing a model's formatters once, they are cached in a static property even across different tests.

Seeding
-------

[](#seeding)

Before seeding your database you'll want to call `setSeeding()`.

```
public function run()
{
    Populator::setSeeding();
```

Its effect is that nullable columns will have a 50% chance of being set to `null` or to the guessed formatter.

Testing
-------

[](#testing)

If `setSeeding()` wasn't called nullable columns will always be set to their guessed formatter. The idea is to simplify tests such as this:

```
public function testSubmitWithoutName() {
    $user = User::factory()->make(['name' => null]);
    // test that submitting a form with $user's attributes causes an error
}

public function testSubmitWithCorrectName() {
    $user = User::factory()->make();
    // no need to specify the correct formatter for name since it can't be null
    // test that submitting a form with $user's attributes is succesful
}
```

On the other hand, seeding the database with `null` attributes lets you notice `Trying to get property of non-object` errors.

###  Health Score

58

—

FairBetter than 98% of packages

Maintenance81

Actively maintained with recent releases

Popularity43

Moderate usage in the ecosystem

Community16

Small or concentrated contributor base

Maturity74

Established project with proven stability

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~121 days

Recently: every ~350 days

Total

29

Last Release

99d ago

Major Versions

v1.2.2 → v2.02017-03-26

v2.1.8 → v3.02020-09-14

PHP version history (3 changes)v1.0.0PHP &gt;=5.6.4

v3.0PHP &gt;=7.4

v3.0.4PHP &gt;=8.1

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/11783568?v=4)[Guido Cella](/maintainers/guidocella)[@guidocella](https://github.com/guidocella)

---

Top Contributors

[![guidocella](https://avatars.githubusercontent.com/u/11783568?v=4)](https://github.com/guidocella "guidocella (120 commits)")

---

Tags

eloquentfakerlaravelphplaravelfakerdatabaseeloquent

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/guidocella-eloquent-populator/health.svg)

```
[![Health](https://phpackages.com/badges/guidocella-eloquent-populator/health.svg)](https://phpackages.com/packages/guidocella-eloquent-populator)
```

###  Alternatives

[mongodb/laravel-mongodb

A MongoDB based Eloquent model and Query builder for Laravel

7.1k8.4M96](/packages/mongodb-laravel-mongodb)[kirschbaum-development/eloquent-power-joins

The Laravel magic applied to joins.

1.6k32.6M46](/packages/kirschbaum-development-eloquent-power-joins)[spiritix/lada-cache

A Redis based, automated and scalable database caching layer for Laravel

592456.3k1](/packages/spiritix-lada-cache)[mvanduijker/laravel-model-exists-rule

Validation rule to check if a model exists

22215.3k2](/packages/mvanduijker-laravel-model-exists-rule)[toponepercent/baum

Baum is an implementation of the Nested Set pattern for Eloquent models.

3262.5k4](/packages/toponepercent-baum)[ntanduy/cloudflare-d1-database

Cloudflare D1 database driver for Laravel — full Eloquent &amp; Query Builder support.

267.8k](/packages/ntanduy-cloudflare-d1-database)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
