Factory
class Factory implements ArrayAccess (View source)
Properties
protected array | $definitions | The model definitions in the container. |
|
protected array | $states | The registered model states. |
|
protected array | $afterMaking | The registered after making callbacks. |
|
protected array | $afterCreating | The registered after creating callbacks. |
|
protected Generator | $faker | The Faker instance for the builder. |
Methods
Create a new factory instance.
Create a new factory container.
Define a class with a given short-name.
Define a class with a given set of attributes.
Define a state with a given set of attributes.
Define a callback to run after making a model.
Define a callback to run after making a model with given state.
Define a callback to run after creating a model.
Define a callback to run after creating a model with given state.
Create an instance of the given model and persist it to the database.
Create an instance of the given model and type and persist it to the database.
Create an instance of the given model.
Create an instance of the given model and type.
Get the raw attribute array for a given named model.
Get the raw attribute array for a given model.
Create a builder for the given model.
Load factories from path.
Determine if the given offset exists.
Get the value of the given offset.
Set the given offset to the given value.
Unset the value at the given offset.
Details
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|array $attributes)
Define a state with a given set of attributes.
$this
afterMaking(string $class, callable $callback, string $name = 'default')
Define a callback to run after making a model.
$this
afterMakingState(string $class, string $state, callable $callback)
Define a callback to run after making a model with given state.
$this
afterCreating(string $class, callable $callback, string $name = 'default')
Define a callback to run after creating a model.
$this
afterCreatingState(string $class, string $state, callable $callback)
Define a callback to run after creating a model with given state.
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.
FactoryBuilder
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.