Factories (are a short name for Models Factories).
Factories are used to generate some fake data with the help of Faker to be used for testing purposes.
Factories are mainly used from Tests.
- Factories SHOULD be created in the Containers.
- A Factory is just a plain PHP script. (No classes or namespaces required)
A User Model Factory:
Tests or anywhere else:
Usage with relationships:
Use make instance of create and pass any data any way, then save after establishing the relations.
Usage while overriding some values:
For more information about the Models Factories read this.