Properties

$definitions

$definitions : array

The model definitions in the container.

Type

array

$class

$class : string

The model being built.

Type

string

$name

$name : string

The name of the model being built.

Type

string

$connection

$connection : string

The database connection on which the model instance should be persisted.

Type

string

$states

$states : array

The model states.

Type

array

$afterMaking

$afterMaking : array

The model after making callbacks.

Type

array

$afterCreating

$afterCreating : array

The model after creating callbacks.

Type

array

$activeStates

$activeStates : array

The states to apply.

Type

array

$faker

$faker : \Faker\Generator

The Faker instance for the builder.

Type

\Faker\Generator

$amount

$amount : integer|null

The number of models to build.

Type

integer|null

Methods

__construct()

__construct(string  $class, string  $name, array  $definitions, array  $states, array  $afterMaking, array  $afterCreating, \Faker\Generator  $faker) : void

Create an new builder instance.

Parameters

string $class
string $name
array $definitions
array $states
array $afterMaking
array $afterCreating
\Faker\Generator $faker

times()

times(integer  $amount) : $this

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

Parameters

integer $amount

Returns

$this

state()

state(string  $state) : $this

Set the state to be applied to the model.

Parameters

string $state

Returns

$this

states()

states(array|mixed  $states) : $this

Set the states to be applied to the model.

Parameters

array|mixed $states

Returns

$this

connection()

connection(string  $name) : $this

Set the database connection on which the model instance should be persisted.

Parameters

string $name

Returns

$this

lazy()

lazy(array  $attributes = array()) : \Closure

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

Parameters

array $attributes

Returns

\Closure

create()

create(array  $attributes = array()) : mixed

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

Parameters

array $attributes

Returns

mixed

make()

make(array  $attributes = array()) : mixed

Create a collection of models.

Parameters

array $attributes

Returns

mixed

raw()

raw(array  $attributes = array()) : mixed

Create an array of raw attribute arrays.

Parameters

array $attributes

Returns

mixed

callAfterMaking()

callAfterMaking(\think\Collection  $models) : void

Run after making callbacks on a collection of models.

Parameters

\think\Collection $models

callAfterCreating()

callAfterCreating(\think\Collection  $models) : void

Run after creating callbacks on a collection of models.

Parameters

\think\Collection $models

store()

store(\think\Collection  $results) : void

Set the connection name on the results and store them.

Parameters

\think\Collection $results

getRawAttributes()

getRawAttributes(array  $attributes = array()) : mixed

Get a raw attributes array for the model.

Parameters

array $attributes

Throws

\InvalidArgumentException

Returns

mixed

makeInstance()

makeInstance(array  $attributes = array()) : \think\Model

Make an instance of the model with the given attributes.

Parameters

array $attributes

Returns

\think\Model

applyStates()

applyStates(array  $definition, array  $attributes = array()) : array

Apply the active states to the model definition array.

Parameters

array $definition
array $attributes

Returns

array

stateAttributes()

stateAttributes(string  $state, array  $attributes) : array

Get the state attributes.

Parameters

string $state
array $attributes

Returns

array

expandAttributes()

expandAttributes(array  $attributes) : array

Expand all attributes to their underlying values.

Parameters

array $attributes

Returns

array

callAfter()

callAfter(array  $afterCallbacks, \think\Collection  $models) : void

Call after callbacks for each model and state.

Parameters

array $afterCallbacks
\think\Collection $models

callAfterCallbacks()

callAfterCallbacks(array  $afterCallbacks, \think\Model  $model, string  $state) : void

Call after callbacks for each model and state.

Parameters

array $afterCallbacks
\think\Model $model
string $state

stateHasAfterCallback()

stateHasAfterCallback(string  $state) : boolean

Determine if the given state has an "after" callback.

Parameters

string $state

Returns

boolean