FactoryBuilder
class FactoryBuilder (View source)
Traits
Macroable |
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 string | $connection | The database connection on which the model instance should be persisted. | |
protected array | $states | The model states. | |
protected array | $afterMaking | The model after making callbacks. | |
protected array | $afterCreating | The model after creating callbacks. | |
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, object|callable $macro) Register a custom macro. | from Macroable |
static void | mixin(object $mixin) Mix another object into the class. | from Macroable |
static bool | hasMacro(string $name) Checks if macro is registered. | from Macroable |
static mixed | __callStatic(string $method, array $parameters) Dynamically handle calls to the class. | from Macroable |
mixed | __call(string $method, array $parameters) Dynamically handle calls to the class. | from Macroable |
void | __construct(string $class, string $name, array $definitions, array $states, array $afterMaking, array $afterCreating, Generator $faker) Create an new builder instance. | |
$this | times(int $amount) Set the amount of models you wish to create / make. | |
$this | state(string $state) Set the state to be applied to the model. | |
$this | states(array|mixed $states) Set the states to be applied to the model. | |
$this | connection(string $name) Set the database connection on which the model instance should be persisted. | |
Closure | 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. | |
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 | stateAttributes(string $state, array $attributes) Get the state attributes. | |
array | expandAttributes(array $attributes) Expand all attributes to their underlying values. | |
void | callAfterMaking(Collection $models) Run after making callbacks on a collection of models. | |
void | callAfterCreating(Collection $models) Run after creating callbacks on a collection of models. | |
void | callAfter(array $afterCallbacks, Collection $models) Call after callbacks for each model and state. | |
void | callAfterCallbacks(array $afterCallbacks, Model $model, string $state) Call after callbacks for each model and state. | |
bool | stateHasAfterCallback(string $state) Determine if the given state has an "after" callback. |
Details
static void macro(string $name, object|callable $macro)
Register a custom macro.
static void mixin(object $mixin)
Mix another object into the class.
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, array $afterMaking, array $afterCreating, Generator $faker)
Create an new builder instance.
$this times(int $amount)
Set the amount of models you wish to create / make.
$this state(string $state)
Set the state to be applied to the model.
$this states(array|mixed $states)
Set the states to be applied to the model.
$this connection(string $name)
Set the database connection on which the model instance should be persisted.
Closure 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.
protected 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.
protected mixed getRawAttributes(array $attributes = [])
Get a raw attributes array for the model.
protected Model makeInstance(array $attributes = [])
Make an instance of the model with the given attributes.
protected array applyStates(array $definition, array $attributes = [])
Apply the active states to the model definition array.
protected array stateAttributes(string $state, array $attributes)
Get the state attributes.
protected array expandAttributes(array $attributes)
Expand all attributes to their underlying values.
void callAfterMaking(Collection $models)
Run after making callbacks on a collection of models.
void callAfterCreating(Collection $models)
Run after creating callbacks on a collection of models.
protected void callAfter(array $afterCallbacks, Collection $models)
Call after callbacks for each model and state.
protected void callAfterCallbacks(array $afterCallbacks, Model $model, string $state)
Call after callbacks for each model and state.
protected bool stateHasAfterCallback(string $state)
Determine if the given state has an "after" callback.
© Taylor Otwell
Licensed under the MIT License.
Laravel is a trademark of Taylor Otwell.
https://laravel.com/api/5.7/Illuminate/Database/Eloquent/FactoryBuilder.html