Factories
Obsolete page
This page requires updating for UserFrosting 6. You can help by contributing on GitHub.
Note
This page is a stub. To contribute to this documentation, please submit a pull request to our learn repository.
Model factories can be used to insert test data into the database. See Laravel Documentation for more information. The only difference si the class your factory need to extend:
- Create your factory, which must extend
UserFrosting\Sprinkle\Core\Database\Factories\Factory; - You model need to use the
Illuminate\Database\Eloquent\Factories\HasFactorytrait; - Add
newFactorymethod in your model, returning your factory:/** * Create a new factory instance for the model. * * @return \Illuminate\Database\Eloquent\Factories\Factory */ protected static function newFactory() { return UserFactory::new(); } - Use the factory :
$user = User::factory()->create();