abstract class Factory (View source)
| Conditionable | |
| ForwardsCalls | |
| Macroable |
| static protected array | $macros | The registered string macros. | from Macroable |
| protected TModel> | $model | The name of the factory's corresponding model. | |
| protected int|null | $count | The number of models that should be generated. | |
| protected Collection | $states | The state transformations that will be applied to the model. | |
| protected Collection | $has | The parent relationships that will be applied to the model. | |
| protected Collection | $for | The child relationships that will be applied to the model. | |
| protected Collection | $recycle | The model instances to always use when creating relationships. | |
| protected Collection | $afterMaking | The "after making" callbacks that will be applied to the model. | |
| protected Collection | $afterCreating | The "after creating" callbacks that will be applied to the model. | |
| protected string|null | $connection | The name of the database connection that will be used to create the models. | |
| protected Generator | $faker | The current Faker instance. | |
| static string | $namespace | The default namespace where factories reside. | |
| static protected | $modelNameResolver | The default model name resolver. | |
| static protected callable | $factoryNameResolver | The factory name resolver. |
| $this|TWhenReturnType | when($value = null, callable|null $callback = null, callable|null $default = null)
Apply the callback if the given "value" is (or resolves to) truthy. | from Conditionable |
| $this|TUnlessReturnType | unless($value = null, callable|null $callback = null, callable|null $default = null)
Apply the callback if the given "value" is (or resolves to) falsy. | from Conditionable |
| mixed | forwardCallTo(mixed $object, string $method, array $parameters)
Forward a method call to the given object. | from ForwardsCalls |
| mixed | forwardDecoratedCallTo(mixed $object, string $method, array $parameters)
Forward a method call to the given object, returning $this if the forwarded call returned itself. | from ForwardsCalls |
| static void | throwBadMethodCallException(string $method)
Throw a bad method call exception for the given method. | from ForwardsCalls |
| static void | macro(string $name, object|callable $macro)
Register a custom macro. | from Macroable |
| static void | mixin(object $mixin, bool $replace = true)
Mix another object into the class. | from Macroable |
| static bool | hasMacro(string $name)
Checks if macro is registered. | from Macroable |
| static void | flushMacros()
Flush the existing macros. | from Macroable |
| static mixed | __callStatic(string $method, array $parameters)
Dynamically handle calls to the class. | from Macroable |
| mixed | __call(string $method, array $parameters)
Proxy dynamic factory methods onto their proper methods. | |
| void | __construct(int|null $count = null, Collection|null $states = null, Collection|null $has = null, Collection|null $for = null, Collection|null $afterMaking = null, Collection|null $afterCreating = null, string|null $connection = null, Collection|null $recycle = null)
Create a new factory instance. | |
| array<string,mixed> | definition()
Define the model's default state. | |
| static Factory | new($attributes = [])
Get a new factory instance for the given attributes. | |
| static Factory | times(int $count)
Get a new factory instance for the given number of models. | |
| Factory | configure()
Configure the factory. | |
| array<int|string,mixed> | raw($attributes = [], Model|null $parent = null)
Get the raw attributes generated by the factory. | |
| TModel | createOne($attributes = [])
Create a single model and persist it to the database. | |
| TModel | createOneQuietly($attributes = [])
Create a single model and persist it to the database without dispatching any model events. | |
| TModel> | createMany(int|iterable|null $records = null)
Create a collection of models and persist them to the database. | |
| TModel> | createManyQuietly(int|iterable|null $records = null)
Create a collection of models and persist them to the database without dispatching any model events. | |
| TModel>|TModel | create($attributes = [], Model|null $parent = null)
Create a collection of models and persist them to the database. | |
| TModel>|TModel | createQuietly($attributes = [], Model|null $parent = null)
Create a collection of models and persist them to the database without dispatching any model events. | |
| lazy(array $attributes = [], Model|null $parent = null) No description | ||
| void | store(Collection $results)
Set the connection name on the results and store them. | |
| void | createChildren(Model $model)
Create the children for the given model. | |
| TModel | makeOne($attributes = [])
Make a single instance of the model. | |
| TModel>|TModel | make($attributes = [], Model|null $parent = null)
Create a collection of models. | |
| Model | makeInstance(Model|null $parent)
Make an instance of the model with the given attributes. | |
| mixed | getExpandedAttributes(Model|null $parent)
Get a raw attributes array for the model. | |
| array | getRawAttributes(Model|null $parent)
Get the raw attributes for the model as an array. | |
| array | parentResolvers()
Create the parent relationship resolvers (as deferred Closures). | |
| array | expandAttributes(array $definition)
Expand all attributes to their underlying values. | |
| Factory | state($state)
Add a new state transformation to the model definition. | |
| Factory | set(string|int $key, mixed $value)
Set a single model attribute. | |
| Factory | sequence(mixed ...$sequence)
Add a new sequenced state transformation to the model definition. | |
| Factory | forEachSequence(array ...$sequence)
Add a new sequenced state transformation to the model definition and update the pending creation count to the size of the sequence. | |
| Factory | crossJoinSequence(array ...$sequence)
Add a new cross joined sequenced state transformation to the model definition. | |
| Factory | has(Factory $factory, string|null $relationship = null)
Define a child relationship for the model. | |
| string | guessRelationship(string $related)
Attempt to guess the relationship name for a "has" relationship. | |
| hasAttached($factory, $pivot = [], $relationship = null) No description | ||
| Factory | for(Factory|Model $factory, string|null $relationship = null)
Define a parent relationship for the model. | |
| Factory | recycle(Model|Collection|array $model)
Provide model instances to use instead of any nested factory calls when creating relationships. | |
| TClass|null | getRandomRecycledModel(TClass> $modelClassName)
Retrieve a random model of a given type from previously provided models to recycle. | |
| Factory | afterMaking(Closure $callback)
Add a new "after making" callback to the model definition. | |
| Factory | afterCreating(Closure $callback)
Add a new "after creating" callback to the model definition. | |
| void | callAfterMaking(Collection $instances)
Call the "after making" callbacks for the given model instances. | |
| void | callAfterCreating(Collection $instances, Model|null $parent = null)
Call the "after creating" callbacks for the given model instances. | |
| Factory | count(int|null $count)
Specify how many models should be generated. | |
| Factory | connection(string $connection)
Specify the database connection that should be used to generate models. | |
| Factory | newInstance(array $arguments = [])
Create a new instance of the factory builder with the given mutated properties. | |
| TModel | newModel(array $attributes = [])
Get a new model instance. | |
| TModel> | modelName()
Get the name of the model that is generated by the factory. | |
| static void | guessModelNamesUsing(callable $callback)
Specify the callback that should be invoked to guess model names based on factory names. | |
| static void | useNamespace(string $namespace)
Specify the default namespace that contains the application's model factories. | |
| static TClass> | factoryForModel(string $modelName)
Get a new factory instance for the given model name. | |
| static void | guessFactoryNamesUsing(callable $callback)
Specify the callback that should be invoked to guess factory names based on dynamic relationship names. | |
| Generator | withFaker()
Get a new Faker instance. | |
| static | resolveFactoryName(string $modelName) No description | |
| static string | appNamespace()
Get the application namespace for the application. | |
| $this | trashed() No description |
Apply the callback if the given "value" is (or resolves to) truthy.
Apply the callback if the given "value" is (or resolves to) falsy.
Forward a method call to the given object.
Forward a method call to the given object, returning $this if the forwarded call returned itself.
Throw a bad method call exception for the given method.
Register a custom macro.
Mix another object into the class.
Checks if macro is registered.
Flush the existing macros.
Dynamically handle calls to the class.
Proxy dynamic factory methods onto their proper methods.
Create a new factory instance.
Define the model's default state.
Get a new factory instance for the given attributes.
Get a new factory instance for the given number of models.
Configure the factory.
Get the raw attributes generated by the factory.
Create a single model and persist it to the database.
Create a single model and persist it to the database without dispatching any model events.
Create a collection of models and persist them to the database.
Create a collection of models and persist them to the database without dispatching any model events.
Create a collection of models and persist them to the database.
Create a collection of models and persist them to the database without dispatching any model events.
No description
Set the connection name on the results and store them.
Create the children for the given model.
Make a single instance of the model.
Create a collection of models.
Make an instance of the model with the given attributes.
Get a raw attributes array for the model.
Get the raw attributes for the model as an array.
Create the parent relationship resolvers (as deferred Closures).
Expand all attributes to their underlying values.
Add a new state transformation to the model definition.
Set a single model attribute.
Add a new sequenced state transformation to the model definition.
Add a new sequenced state transformation to the model definition and update the pending creation count to the size of the sequence.
Add a new cross joined sequenced state transformation to the model definition.
Define a child relationship for the model.
Attempt to guess the relationship name for a "has" relationship.
No description
Define a parent relationship for the model.
Provide model instances to use instead of any nested factory calls when creating relationships.
Retrieve a random model of a given type from previously provided models to recycle.
Add a new "after creating" callback to the model definition.
Call the "after making" callbacks for the given model instances.
Call the "after creating" callbacks for the given model instances.
Specify how many models should be generated.
Specify the database connection that should be used to generate models.
Create a new instance of the factory builder with the given mutated properties.
Get a new model instance.
Get the name of the model that is generated by the factory.
Specify the callback that should be invoked to guess model names based on factory names.
Specify the default namespace that contains the application's model factories.
Get a new factory instance for the given model name.
Specify the callback that should be invoked to guess factory names based on dynamic relationship names.
Get a new Faker instance.
No description
Get the application namespace for the application.
No description
© Taylor Otwell
Licensed under the MIT License.
Laravel is a trademark of Taylor Otwell.
https://laravel.com/api/11.x/Illuminate/Database/Eloquent/Factories/Factory.html