FactoryBuilder
class FactoryBuilder (View source)
Traits
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
Mix another object into the class.
Dynamically handle calls to the class.
Dynamically handle calls to the class.
Create an new builder instance.
Set the amount of models you wish to create / make.
Set the state to be applied to the model.
Set the states to be applied to the model.
Set the database connection on which the model instance should be persisted.
Create a collection of models and persist them to the database.
Create a collection of models and persist them to the database.
Create a collection of models.
Create an array of raw attribute arrays.
Get a raw attributes array for the model.
Make an instance of the model with the given attributes.
Apply the active states to the model definition array.
Get the state attributes.
Expand all attributes to their underlying values.
Call after callbacks for each model and 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, bool $replace = true)
        
    
    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.
        
                            Collection|Model|mixed
    create(array $attributes = [])
        
    
    Create a collection of models and persist them to the database.
        
                            Collection|mixed
    createMany(iterable $records)
        
    
    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.
        
                            Collection|Model|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.