Videos
If you want the make:factory command to generate a factory class for an existing model, you need to tell it which model to use with the --model option:
Copyphp artisan make:factory AddressFactory --model="App\\Address"
For Laravel 8
With the artisan command, you no longer need to specify the model. By automatically including the factory trait in the model, Laravel automatically makes the factory methods available to the corresponding model.
So only:
php artisan make:factory AddressFactory
It is then sufficient to call the model in the seeder or in the tests.
For example:
App\Models\Address::factory(10)->create();
Model & Factory Discovery Conventions
Once you have defined your factories, you may use the static factory method provided to your models by the Illuminate\Database\Eloquent\Factories\HasFactory trait in order to instantiate a factory instance for that model.
The HasFactory trait's factory method will use conventions to determine the proper factory for the model the trait is assigned to. Specifically, the method will look for a factory in the Database\Factories namespace that has a class name matching the model name and is suffixed with Factory. If these conventions do not apply to your particular application or factory, you may overwrite the newFactory method on your model to return an instance of the model's corresponding factory directly: