Properties

$definitions

$definitions : array

The model definitions in the container.

Type

array

$states

$states : array

The registered model states.

Type

array

$afterMaking

$afterMaking : array

The registered after making callbacks.

Type

array

$afterCreating

$afterCreating : array

The registered after creating callbacks.

Type

array

$faker

$faker : \Faker\Generator

The Faker instance for the builder.

Type

\Faker\Generator

Methods

__construct()

__construct(\Faker\Generator  $faker) : void

Create a new factory instance.

Parameters

\Faker\Generator $faker

defineAs()

defineAs(string  $class, string  $name, callable  $attributes) : $this

Define a class with a given short-name.

Parameters

string $class
string $name
callable $attributes

Returns

$this

define()

define(string  $class, callable  $attributes, string  $name = 'default') : $this

Define a class with a given set of attributes.

Parameters

string $class
callable $attributes
string $name

Returns

$this

state()

state(string  $class, string  $state, callable|array  $attributes) : $this

Define a state with a given set of attributes.

Parameters

string $class
string $state
callable|array $attributes

Returns

$this

afterMaking()

afterMaking(string  $class, callable  $callback, string  $name = 'default') : $this

Define a callback to run after making a model.

Parameters

string $class
callable $callback
string $name

Returns

$this

afterMakingState()

afterMakingState(string  $class, string  $state, callable  $callback) : $this

Define a callback to run after making a model with given state.

Parameters

string $class
string $state
callable $callback

Returns

$this

afterCreating()

afterCreating(string  $class, callable  $callback, string  $name = 'default') : $this

Define a callback to run after creating a model.

Parameters

string $class
callable $callback
string $name

Returns

$this

afterCreatingState()

afterCreatingState(string  $class, string  $state, callable  $callback) : $this

Define a callback to run after creating a model with given state.

Parameters

string $class
string $state
callable $callback

Returns

$this

create()

create(string  $class, array  $attributes = array()) : mixed

Create an instance of the given model and persist it to the database.

Parameters

string $class
array $attributes

Returns

mixed

createAs()

createAs(string  $class, string  $name, array  $attributes = array()) : mixed

Create an instance of the given model and type and persist it to the database.

Parameters

string $class
string $name
array $attributes

Returns

mixed

make()

make(string  $class, array  $attributes = array()) : mixed

Create an instance of the given model.

Parameters

string $class
array $attributes

Returns

mixed

makeAs()

makeAs(string  $class, string  $name, array  $attributes = array()) : mixed

Create an instance of the given model and type.

Parameters

string $class
string $name
array $attributes

Returns

mixed

rawOf()

rawOf(string  $class, string  $name, array  $attributes = array()) : array

Get the raw attribute array for a given named model.

Parameters

string $class
string $name
array $attributes

Returns

array

raw()

raw(string  $class, array  $attributes = array(), string  $name = 'default') : array

Get the raw attribute array for a given model.

Parameters

string $class
array $attributes
string $name

Returns

array

of()

of(string  $class, string  $name = 'default') : \think\migration\FactoryBuilder

Create a builder for the given model.

Parameters

string $class
string $name

Returns

\think\migration\FactoryBuilder

load()

load(string  $path) : $this

Load factories from path.

Parameters

string $path

Returns

$this

offsetExists()

offsetExists(string  $offset) : boolean

Determine if the given offset exists.

Parameters

string $offset

Returns

boolean

offsetGet()

offsetGet(string  $offset) : mixed

Get the value of the given offset.

Parameters

string $offset

Returns

mixed

offsetSet()

offsetSet(string  $offset, callable  $value) : void

Set the given offset to the given value.

Parameters

string $offset
callable $value

offsetUnset()

offsetUnset(string  $offset) : void

Unset the value at the given offset.

Parameters

string $offset