class FactoryBuilder

Traits

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.

static bool
hasMacro(string $name)

Checks if macro is registered.

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

Dynamically handle calls to the class.

mixed
__call(string $method, array $parameters)

Dynamically handle calls to the class.

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.

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.

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

in Macroable at line 24
static void macro(string $name, callable $macro)

Register a custom macro.

Parameters

string $name
callable $macro

Return Value

void

in Macroable at line 35
static bool hasMacro(string $name)

Checks if macro is registered.

Parameters

string $name

Return Value

bool

in Macroable at line 49
static mixed __callStatic(string $method, array $parameters)

Dynamically handle calls to the class.

Parameters

string $method
array $parameters

Return Value

mixed

Exceptions

BadMethodCallException

in Macroable at line 71
mixed __call(string $method, array $parameters)

Dynamically handle calls to the class.

Parameters

string $method
array $parameters

Return Value

mixed

Exceptions

BadMethodCallException

at line 72
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

at line 87
$this times(int $amount)

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

Parameters

int $amount

Return Value

$this

at line 100
$this states(array|mixed $states)

Set the states to be applied to the model.

Parameters

array|mixed $states

Return Value

$this

at line 113
Closure lazy(array $attributes = [])

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

Parameters

array $attributes

Return Value

Closure

at line 126
mixed create(array $attributes = [])

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

Parameters

array $attributes

Return Value

mixed

at line 145
protected void store(Collection $results)

Set the connection name on the results and store them.

Parameters

Collection $results

Return Value

void

at line 160
mixed make(array $attributes = [])

Create a collection of models.

Parameters

array $attributes

Return Value

mixed

at line 181
mixed raw(array $attributes = [])

Create an array of raw attribute arrays.

Parameters

array $attributes

Return Value

mixed

at line 202
protected mixed getRawAttributes(array $attributes = [])

Get a raw attributes array for the model.

Parameters

array $attributes

Return Value

mixed

at line 222
protected Model makeInstance(array $attributes = [])

Make an instance of the model with the given attributes.

Parameters

array $attributes

Return Value

Model

Exceptions

InvalidArgumentException

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

Apply the active states to the model definition array.

Parameters

array $definition
array $attributes

Return Value

array

at line 264
protected array expandAttributes(array $attributes)

Expand all attributes to their underlying values.

Parameters

array $attributes

Return Value

array