Skip to content

Latest commit

 

History

History
25 lines (22 loc) · 1.02 KB

File metadata and controls

25 lines (22 loc) · 1.02 KB
title taxonomy
Factories
category
docs

[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:

  1. Create your factory, which must extend UserFrosting\Sprinkle\Core\Database\Factories\Factory;
  2. You model need to use the Illuminate\Database\Eloquent\Factories\HasFactory trait;
  3. 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();
     }
  4. Use the factory : $user = User::factory()->create();