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(1mo ago)7661.6k↓45.6%92MITPHP

Since Dec 16Pushed 1mo 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 1mo 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

60

—

FairBetter than 99% of packages

Maintenance89

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

54d 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://www.gravatar.com/avatar/57ac25d75f252597a91810b12597248e09a8fd4338014435dc3ee0bfd8dca5ee?d=identicon)[guidocella](/maintainers/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.1k7.2M71](/packages/mongodb-laravel-mongodb)[spiritix/lada-cache

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

591444.8k2](/packages/spiritix-lada-cache)[pdphilip/elasticsearch

An Elasticsearch implementation of Laravel's Eloquent ORM

145360.2k4](/packages/pdphilip-elasticsearch)[mvanduijker/laravel-transactional-model-events

Add eloquent model events fired after a transaction is committed or rolled back

75164.5k](/packages/mvanduijker-laravel-transactional-model-events)[gearbox-solutions/eloquent-filemaker

A package for getting FileMaker records as Eloquent models in Laravel

6454.8k2](/packages/gearbox-solutions-eloquent-filemaker)[mvanduijker/laravel-model-exists-rule

Validation rule to check if a model exists

22194.5k1](/packages/mvanduijker-laravel-model-exists-rule)

PHPackages © 2026

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