Download the PHP package anahkiasen/fakable without Composer
On this page you can find all versions of the php package anahkiasen/fakable. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download anahkiasen/fakable
More information about anahkiasen/fakable
Files in anahkiasen/fakable
Package fakable
Short Description Allows the creation and seeding of fake Eloquent models
License
Informations about the package fakable
DEPRECATED
This package is deprecated and will no longer be maintained, I recommend using Factory Muffin instead
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
Usage
Basic usage
Simply add the trait to a model like this :
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 :
Fakable uses 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 :
You can also generate multiple models by calling fakeMultiple(attributes, min, max)
:
Advanced usage
To get more control over the flow of your generated fake models you can do this :
This will return a Fakable instance from which you can set various options :
Setting attributes on fake models
You can also set attributes on generated fake models that may not be random :
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.
You can also set a different file for a specific Fakable instance, like this per example:
The file is a simple array [class => attributes] like this:
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 :
Optionally you can pass a number of generated relations to generate by passing a min and/or max :
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 :
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 :
All versions of fakable with dependencies
illuminate/support Version ~4
fzaninotto/faker Version ~1.4
symfony/yaml Version ~2.6