1. Home
  2. Docs
  3. laravel
  4. “php artisan make:&...
  5. artisan make:factory

artisan make:factory

PURPOSE

  • Factories are used to create multiple records in a table
  • When testing, you may need to insert a few records into your database before executing your test. Instead of manually specifying the value of each column when you create this test data, Laravel allows you to define a default set of attributes for each of your Eloquent models using model factories. To get started, take a look at the database/factories/UserFactory.php file in your application. Out of the box, this file contains one factory definition:

USAGE

> php artisan make:factory 
Description:
   Create a new model factory
 
 Usage:
   make:factory [options] [--] <name>
 
 Arguments:
   name                  The name of the class
 
 Options:
   -m, --model[=MODEL]   The name of the model
   -h, --help            Display this help message
   -q, --quiet           Do not output any message
   -V, --version         Display this application version
       --ansi            Force ANSI output
       --no-ansi         Disable ANSI output
   -n, --no-interaction  Do not ask any interactive question
       --env[=ENV]       The environment the command should run under
   -v|vv|vvv, --verbose  Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug 

Reference: https://laravel.com/docs/6.x/database-testing#writing-factories