FactoryBuilder

class FactoryBuilder (View source)

Traits

Macroable

Properties

static protected array $macros The registered string macros. from Macroable
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 array $states The model states.
protected array $activeStates The states to apply.
protected Generator $faker The Faker instance for the builder.
protected int|null $amount The number of models to build.

Methods

static void macro(string $name, callable $macro)

Register a custom macro.

from Macroable
static bool hasMacro(string $name)

Checks if macro is registered.

from Macroable
static mixed __callStatic(string $method, array $parameters)

Dynamically handle calls to the class.

from Macroable
mixed __call(string $method, array $parameters)

Dynamically handle calls to the class.

from Macroable
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|mixed $states)

Set the states to be applied to the model.

Closure lazy(array $attributes = [])

Create a model and persist it in the database if requested.

mixed create(array $attributes = [])

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

void store(Collection $results)

Set the connection name on the results and store them.

mixed make(array $attributes = [])

Create a collection of models.

mixed raw(array $attributes = [])

Create an array of raw attribute arrays.

mixed getRawAttributes(array $attributes = [])

Get a raw attributes array for the model.

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 expandAttributes(array $attributes)

Expand all attributes to their underlying values.

Details

static void macro(string $name, callable $macro)

Register a custom macro.

Parameters

string $name
callable $macro

Return Value

void

static bool hasMacro(string $name)

Checks if macro is registered.

Parameters

string $name

Return Value

bool

static mixed __callStatic(string $method, array $parameters)

Dynamically handle calls to the class.

Parameters

string $method
array $parameters

Return Value

mixed

Exceptions

BadMethodCallException

mixed __call(string $method, array $parameters)

Dynamically handle calls to the class.

Parameters

string $method
array $parameters

Return Value

mixed

Exceptions

BadMethodCallException

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|mixed $states)

Set the states to be applied to the model.

Parameters

array|mixed $states

Return Value

$this

Closure lazy(array $attributes = [])

Create a model and persist it in the database if requested.

Parameters

array $attributes

Return Value

Closure

mixed create(array $attributes = [])

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

Parameters

array $attributes

Return Value

mixed

protected void store(Collection $results)

Set the connection name on the results and store them.

Parameters

Collection $results

Return Value

void

mixed make(array $attributes = [])

Create a collection of models.

Parameters

array $attributes

Return Value

mixed

mixed raw(array $attributes = [])

Create an array of raw attribute arrays.

Parameters

array $attributes

Return Value

mixed

protected mixed getRawAttributes(array $attributes = [])

Get a raw attributes array for the model.

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 expandAttributes(array $attributes)

Expand all attributes to their underlying values.

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.4/Illuminate/Database/Eloquent/FactoryBuilder.html