PHPackages                             anahkiasen/fakable - 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. anahkiasen/fakable

Abandoned → [thephpleague/factory-muffin](/?search=thephpleague%2Ffactory-muffin)Library[Database &amp; ORM](/categories/database)

anahkiasen/fakable
==================

Allows the creation and seeding of fake Eloquent models

1.3.4(9y ago)2412.7k1PHPPHP &gt;=5.4.0

Since Apr 3Pushed 9y agoCompare

[ Source](https://github.com/Anahkiasen/fakable)[ Packagist](https://packagist.org/packages/anahkiasen/fakable)[ RSS](/packages/anahkiasen-fakable/feed)WikiDiscussions master Synced today

READMEChangelogDependencies (6)Versions (9)Used By (0)

DEPRECATED
==========

[](#deprecated)

This package is deprecated and will no longer be maintained, I recommend using [Factory Muffin](https://github.com/thephpleague/factory-muffin) instead
-------------------------------------------------------------------------------------------------------------------------------------------------------

[](#this-package-is-deprecated-and-will-no-longer-be-maintained-i-recommend-using-factory-muffin-instead)

Fakable
=======

[](#fakable)

Allows the creation and seeding of fake Eloquent models. This is a PHP 5.4+ package.

Can be used in tests or to generate batch of fake entries in the seeds.

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

[](#installation)

```
$ composer require anahkiasen/fakable:dev-master

```

Usage
-----

[](#usage)

### Basic usage

[](#basic-usage)

Simply add the trait to a model like this :

```
use Fakable\FakableModel;

class MyModel extends Eloquent
{
  use FakableModel;
}
```

A lot of defaults are built-in to configure what gets assigned to what attribute, but you can override or add to this by modifing the `$fakable` property on your model :

```
class User extends Eloquent
{
  /**
   * The fakable attributes
   *
   * @var array
   */
  protected $fakables = array(
    'nationality' => 'countryCode',
    'timzeone'    => ['numberBetween', [1, 415]],
  );
}
```

Fakable uses [Faker](https://github.com/fzaninotto/Faker) underneath so you can call any of Faker's methods by either simply passing a method name, or an array of `['method', [argument, argument]]` as seen above.

From then on you can call multiple methods on the model to generate fake instances :

```
> User::fake()->toArray();
array(
  'id'          => 28,
  'name'        => 'Tempore ipsa aut dolorum sit quod.',
  'slug'        => 'tempore-ipsa-aut-dolorum-sit-quod',
  'age'         => 23,
  'biography'   => 'Culpa debitis dolorem quidem eius. Quis et voluptatibus est. Quia nulla rerum expedita magnam.',
  'email'       => 'nienow.donnie@spinkawisoky.com',
  'website'     => 'http://www.weissnat.com/',
  'address'     => '91274 Schmitt Light Suite 378',
  'country'     => 'Sudan',
  'city'        => 'North Twila',
  'private'     => false,
  'nationality' => 'RU'
)
```

You can also generate multiple models by calling `fakeMultiple(attributes, min, max)` :

```
User::fakeMultiple(array(
  'name' => 'foobar',
), 5, 10);

User::count() // 7
```

Advanced usage
--------------

[](#advanced-usage)

To get more control over the flow of your generated fake models you can do this :

```
User::fakable()
```

This will return a Fakable instance from which you can set various options :

```
User::fakable()
  ->setPool(10, 20) // Will generate 10 to 20 entries
  ->setPoolFromModel('Discussion', 2) // Will generate 2 users for every discussion
  ->setSaved(false) // Won't save anything to the database
  ->fakeModel() // Generated a single fake model, that's what ::fake() calls
  ->fakeMultiple() // Generate multiple models from the pool set previously
```

### Setting attributes on fake models

[](#setting-attributes-on-fake-models)

You can also set attributes on generated fake models that may not be random :

```
User::fakable()->fakeMultiple(array(
  'gender' => 'Male',
));
```

Attributes fixtures
-------------------

[](#attributes-fixtures)

Instead of setting all your attributes on your models you can also create an attributes fixture to hold them all. This file can be anywhere and can be either a PHP, YAML or JSON file. You tell Fakable where to find it by setting the `Fakable\Fakable::$baseFixture` variable to its path, in the setup of your seeding per example, or the start of your application.

```
Fakable\Fakable::$baseFixture = app_path().'/tests/fixtures/fakable.yml';
```

You can also set a different file for a specific Fakable instance, like this per example:

```
User::fakable()->setFixture(__DIR__.'/fixtures/user.json')->fakeModel()
```

The file is a simple array \[class =&gt; attributes\] like this:

```
User:
  name: 'name'
  age: ['numberBetween', [0, 20]]
```

Relationships
-------------

[](#relationships)

Fakable will also seed relationships when possible. Most of the time this is a completely automatic process, you simply add the name of the relationship to the fakable attributes and pass it an empty signature :

```
protected $fakables = array(
  'discussions' => [],
);
```

Optionally you can pass a number of generated relations to generate by passing a min and/or max :

```
protected $fakables = array(
  'discussions' => [10, 20],
);
```

Do note, **this currently doesn't work for Has-type relations** : Fakable can only seed from the point of the receiver (ie Belongs-type relations).

The only relation you *really* need to configure are `morphTo` relations because, well, it's a pain to guess their behavior :

```
class Image extends Eloquent
{
  protected $fakables = array(
    'illustrable' => [
      'relationType' => 'MorphTo',
      'forModels'    => ['User', 'Discussion']
    ],
  );
}
```

Here, `relationType` will tell Fakable this is a MorphTo relationship, and `forModels` will indicate it what kind of models Image may be a polymorphic relation of.

By default Fakable will use the attribute name as the foreign key (so `illustrable` would look for `illustrable_type` and `illustrable_id`) but you can also pass a `foreignKey` to the signature to specify that :

```
class Image extends Eloquent
{
  protected $fakables = array(
    'illustrable' => [
      'foreignKey'   => 'imageable',
      'relationType' => 'MorphTo',
      'forModels'    => ['User', 'Discussion']
    ],
  );
}
```

###  Health Score

34

—

LowBetter than 77% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity29

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity63

Established project with proven stability

 Bus Factor1

Top contributor holds 97.3% 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 ~112 days

Recently: every ~165 days

Total

8

Last Release

3637d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/aa3be3e9e416053f11f2296a5fb36f24e45bc70fa293b309d54c2829ded5f373?d=identicon)[Anahkiasen](/maintainers/Anahkiasen)

---

Top Contributors

[![Anahkiasen](https://avatars.githubusercontent.com/u/1321596?v=4)](https://github.com/Anahkiasen "Anahkiasen (36 commits)")[![dieterve](https://avatars.githubusercontent.com/u/313404?v=4)](https://github.com/dieterve "dieterve (1 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/anahkiasen-fakable/health.svg)

```
[![Health](https://phpackages.com/badges/anahkiasen-fakable/health.svg)](https://phpackages.com/packages/anahkiasen-fakable)
```

###  Alternatives

[illuminate/database

The Illuminate Database package.

2.8k52.4M9.4k](/packages/illuminate-database)[ryangjchandler/orbit

A flat-file database driver for Eloquent.

922256.2k5](/packages/ryangjchandler-orbit)[clickbar/laravel-magellan

This package provides functionality for working with the postgis extension in Laravel.

423715.4k1](/packages/clickbar-laravel-magellan)[genealabs/laravel-pivot-events

This package introduces new eloquent events for sync(), attach(), detach() or updateExistingPivot() methods on BelongsToMany relation.

1404.9M8](/packages/genealabs-laravel-pivot-events)[highsolutions/eloquent-sequence

A Laravel package for easy creation and management sequence support for Eloquent models with elastic configuration.

121130.3k](/packages/highsolutions-eloquent-sequence)[illuminatech/config

Provides support for Laravel application runtime configuration managed in persistent storage

14921.0k1](/packages/illuminatech-config)

PHPackages © 2026

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