Seeding and Making Factories in Laravel 8

Make Factory:

 

php artisan make:factory UserFactory

 

return [

'name'=>$this-faker-name,

];

 

Seeding:

\App\Models\User::factory(10)->create();

 

php artisan db:seed

 

to connect to another model, you can say for example:

'profile_id' => User::all()->random()->id 

 

or use the factory of that model.

 

 

 

Sources & More Details:
Edit this note