class Factory implements ArrayAccess

Properties

protected array $definitions

The model definitions in the container.

protected array $states

The registered model states.

protected Generator $faker

The Faker instance for the builder.

Methods

void
__construct(Generator $faker)

Create a new factory instance.

static Factory
construct(Generator $faker, string|null $pathToFactories = null)

Create a new factory container.

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

Define a class with a given short-name.

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

Define a class with a given set of attributes.

$this
state(string $class, string $state, callable $attributes)

Define a state with a given set of attributes.

mixed
create(string $class, array $attributes = [])

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

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

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

mixed
make(string $class, array $attributes = [])

Create an instance of the given model.

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

Create an instance of the given model and type.

array
rawOf(string $class, string $name, array $attributes = [])

Get the raw attribute array for a given named model.

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

Get the raw attribute array for a given model.

of(string $class, string $name = 'default')

Create a builder for the given model.

$this
load(string $path)

Load factories from path.

bool
offsetExists(string $offset)

Determine if the given offset exists.

mixed
offsetGet(string $offset)

Get the value of the given offset.

void
offsetSet(string $offset, callable $value)

Set the given offset to the given value.

void
offsetUnset(string $offset)

Unset the value at the given offset.

Details

at line 38
void __construct(Generator $faker)

Create a new factory instance.

Parameters

Generator $faker

Return Value

void

at line 50
static Factory construct(Generator $faker, string|null $pathToFactories = null)

Create a new factory container.

Parameters

Generator $faker
string|null $pathToFactories

Return Value

Factory

at line 65
$this defineAs(string $class, string $name, callable $attributes)

Define a class with a given short-name.

Parameters

string $class
string $name
callable $attributes

Return Value

$this

at line 78
$this define(string $class, callable $attributes, string $name = 'default')

Define a class with a given set of attributes.

Parameters

string $class
callable $attributes
string $name

Return Value

$this

at line 93
$this state(string $class, string $state, callable $attributes)

Define a state with a given set of attributes.

Parameters

string $class
string $state
callable $attributes

Return Value

$this

at line 107
mixed create(string $class, array $attributes = [])

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

Parameters

string $class
array $attributes

Return Value

mixed

at line 120
mixed createAs(string $class, string $name, array $attributes = [])

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

Parameters

string $class
string $name
array $attributes

Return Value

mixed

at line 132
mixed make(string $class, array $attributes = [])

Create an instance of the given model.

Parameters

string $class
array $attributes

Return Value

mixed

at line 145
mixed makeAs(string $class, string $name, array $attributes = [])

Create an instance of the given model and type.

Parameters

string $class
string $name
array $attributes

Return Value

mixed

at line 158
array rawOf(string $class, string $name, array $attributes = [])

Get the raw attribute array for a given named model.

Parameters

string $class
string $name
array $attributes

Return Value

array

at line 171
array raw(string $class, array $attributes = [], string $name = 'default')

Get the raw attribute array for a given model.

Parameters

string $class
array $attributes
string $name

Return Value

array

at line 185
FactoryBuilder of(string $class, string $name = 'default')

Create a builder for the given model.

Parameters

string $class
string $name

Return Value

FactoryBuilder

at line 196
$this load(string $path)

Load factories from path.

Parameters

string $path

Return Value

$this

at line 215
bool offsetExists(string $offset)

Determine if the given offset exists.

Parameters

string $offset

Return Value

bool

at line 226
mixed offsetGet(string $offset)

Get the value of the given offset.

Parameters

string $offset

Return Value

mixed

at line 238
void offsetSet(string $offset, callable $value)

Set the given offset to the given value.

Parameters

string $offset
callable $value

Return Value

void

at line 249
void offsetUnset(string $offset)

Unset the value at the given offset.

Parameters

string $offset

Return Value

void