FactoryBuilder
in package
Uses
Macroable
Table of Contents
- $activeStates : array<string|int, mixed>
- The states to apply.
- $amount : int|null
- The number of models to build.
- $class : string
- The model being built.
- $connection : string
- The database connection on which the model instance should be persisted.
- $definitions : array<string|int, mixed>
- The model definitions in the container.
- $faker : Generator
- The Faker instance for the builder.
- $macros : array<string|int, mixed>
- The registered string macros.
- $name : string
- The name of the model being built.
- $states : array<string|int, mixed>
- The model states.
- __call() : mixed
- Dynamically handle calls to the class.
- __callStatic() : mixed
- Dynamically handle calls to the class.
- __construct() : void
- Create an new builder instance.
- connection() : $this
- Set the database connection on which the model instance should be persisted.
- create() : mixed
- Create a collection of models and persist them to the database.
- hasMacro() : bool
- Checks if macro is registered.
- lazy() : Closure
- Create a model and persist it in the database if requested.
- macro() : void
- Register a custom macro.
- make() : mixed
- Create a collection of models.
- mixin() : void
- Mix another object into the class.
- raw() : mixed
- Create an array of raw attribute arrays.
- states() : $this
- Set the states to be applied to the model.
- times() : $this
- Set the amount of models you wish to create / make.
- applyStates() : array<string|int, mixed>
- Apply the active states to the model definition array.
- expandAttributes() : array<string|int, mixed>
- Expand all attributes to their underlying values.
- getRawAttributes() : mixed
- Get a raw attributes array for the model.
- makeInstance() : Model
- Make an instance of the model with the given attributes.
- stateAttributes() : array<string|int, mixed>
- Get the state attributes.
- store() : void
- Set the connection name on the results and store them.
Properties
$activeStates
The states to apply.
protected
array<string|int, mixed>
$activeStates
= []
$amount
The number of models to build.
protected
int|null
$amount
= null
$class
The model being built.
protected
string
$class
$connection
The database connection on which the model instance should be persisted.
protected
string
$connection
$definitions
The model definitions in the container.
protected
array<string|int, mixed>
$definitions
$faker
The Faker instance for the builder.
protected
Generator
$faker
$macros
The registered string macros.
protected
static array<string|int, mixed>
$macros
= []
$name
The name of the model being built.
protected
string
$name
= 'default'
$states
The model states.
protected
array<string|int, mixed>
$states
Methods
__call()
Dynamically handle calls to the class.
public
__call(string $method, array<string|int, mixed> $parameters) : mixed
Parameters
- $method : string
- $parameters : array<string|int, mixed>
Tags
Return values
mixed —__callStatic()
Dynamically handle calls to the class.
public
static __callStatic(string $method, array<string|int, mixed> $parameters) : mixed
Parameters
- $method : string
- $parameters : array<string|int, mixed>
Tags
Return values
mixed —__construct()
Create an new builder instance.
public
__construct(string $class, string $name, array<string|int, mixed> $definitions, array<string|int, mixed> $states, Generator $faker) : void
Parameters
- $class : string
- $name : string
- $definitions : array<string|int, mixed>
- $states : array<string|int, mixed>
- $faker : Generator
Return values
void —connection()
Set the database connection on which the model instance should be persisted.
public
connection(string $name) : $this
Parameters
- $name : string
Return values
$this —create()
Create a collection of models and persist them to the database.
public
create([array<string|int, mixed> $attributes = [] ]) : mixed
Parameters
- $attributes : array<string|int, mixed> = []
Return values
mixed —hasMacro()
Checks if macro is registered.
public
static hasMacro(string $name) : bool
Parameters
- $name : string
Return values
bool —lazy()
Create a model and persist it in the database if requested.
public
lazy([array<string|int, mixed> $attributes = [] ]) : Closure
Parameters
- $attributes : array<string|int, mixed> = []
Return values
Closure —macro()
Register a custom macro.
public
static macro(string $name, object|callable $macro) : void
Parameters
- $name : string
- $macro : object|callable
Return values
void —make()
Create a collection of models.
public
make([array<string|int, mixed> $attributes = [] ]) : mixed
Parameters
- $attributes : array<string|int, mixed> = []
Return values
mixed —mixin()
Mix another object into the class.
public
static mixin(object $mixin) : void
Parameters
- $mixin : object
Return values
void —raw()
Create an array of raw attribute arrays.
public
raw([array<string|int, mixed> $attributes = [] ]) : mixed
Parameters
- $attributes : array<string|int, mixed> = []
Return values
mixed —states()
Set the states to be applied to the model.
public
states(array<string|int, mixed>|mixed $states) : $this
Parameters
- $states : array<string|int, mixed>|mixed
Return values
$this —times()
Set the amount of models you wish to create / make.
public
times(int $amount) : $this
Parameters
- $amount : int
Return values
$this —applyStates()
Apply the active states to the model definition array.
protected
applyStates(array<string|int, mixed> $definition[, array<string|int, mixed> $attributes = [] ]) : array<string|int, mixed>
Parameters
- $definition : array<string|int, mixed>
- $attributes : array<string|int, mixed> = []
Return values
array<string|int, mixed> —expandAttributes()
Expand all attributes to their underlying values.
protected
expandAttributes(array<string|int, mixed> $attributes) : array<string|int, mixed>
Parameters
- $attributes : array<string|int, mixed>
Return values
array<string|int, mixed> —getRawAttributes()
Get a raw attributes array for the model.
protected
getRawAttributes([array<string|int, mixed> $attributes = [] ]) : mixed
Parameters
- $attributes : array<string|int, mixed> = []
Return values
mixed —makeInstance()
Make an instance of the model with the given attributes.
protected
makeInstance([array<string|int, mixed> $attributes = [] ]) : Model
Parameters
- $attributes : array<string|int, mixed> = []
Tags
Return values
Model —stateAttributes()
Get the state attributes.
protected
stateAttributes(string $state, array<string|int, mixed> $attributes) : array<string|int, mixed>
Parameters
- $state : string
- $attributes : array<string|int, mixed>
Return values
array<string|int, mixed> —store()
Set the connection name on the results and store them.
protected
store(Collection $results) : void
Parameters
- $results : Collection