title | taxonomy | ||
---|---|---|---|
Factories |
|
[notice]This page is a stub. To contribute to this documentation, please submit a pull request to our learn repository.[/notice]
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\HasFactory
trait; - Add
newFactory
method 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();