FactoryBuilder

class FactoryBuilder (View source)

Properties

protected array $definitions The model definitions in the container.
protected string $class The model being built.
protected string $name The name of the model being built.
protected int $amount The number of models to build.
protected array $states The model states.
protected array $activeStates The states to apply.
protected Generator $faker The Faker instance for the builder.

Methods

void __construct(string $class, string $name, array $definitions, array $states, Generator $faker)

Create an new builder instance.

$this times(int $amount)

Set the amount of models you wish to create / make.

$this states(array|dynamic $states)

Set the states to be applied to the model.

mixed create(array $attributes = [])

Create a collection of models and persist them to the database.

mixed make(array $attributes = [])

Create a collection of models.

Model makeInstance(array $attributes = [])

Make an instance of the model with the given attributes.

array applyStates(array $definition, array $attributes = [])

Apply the active states to the model definition array.

array callClosureAttributes(array $attributes)

Evaluate any Closure attributes on the attribute array.

Details

void __construct(string $class, string $name, array $definitions, array $states, Generator $faker)

Create an new builder instance.

Parameters

string $class
string $name
array $definitions
array $states
Generator $faker

Return Value

void

$this times(int $amount)

Set the amount of models you wish to create / make.

Parameters

int $amount

Return Value

$this

$this states(array|dynamic $states)

Set the states to be applied to the model.

Parameters

array|dynamic $states

Return Value

$this

mixed create(array $attributes = [])

Create a collection of models and persist them to the database.

Parameters

array $attributes

Return Value

mixed

mixed make(array $attributes = [])

Create a collection of models.

Parameters

array $attributes

Return Value

mixed

protected Model makeInstance(array $attributes = [])

Make an instance of the model with the given attributes.

Parameters

array $attributes

Return Value

Model

Exceptions

InvalidArgumentException

protected array applyStates(array $definition, array $attributes = [])

Apply the active states to the model definition array.

Parameters

array $definition
array $attributes

Return Value

array

protected array callClosureAttributes(array $attributes)

Evaluate any Closure attributes on the attribute array.

Parameters

array $attributes

Return Value

array

© Taylor Otwell
Licensed under the MIT License.
Laravel is a trademark of Taylor Otwell.
https://laravel.com/api/5.3/Illuminate/Database/Eloquent/FactoryBuilder.html