Video Course

Build a Monthly Subscription App with Laravel Cashier: Lesson 3 of 36

Model Factories

Up Next


Autoplaying in 7 seconds!


Create a Free Account to Watch

Sign Up Now

Login to your account

Model factories are a great feature of Laravel that will help us get information into our database. Normally we would create a list of users and then insert them into our database using a seeder.

Here's an example of inserting data into our database without model factories:

$users = [
    ['name' => 'Chris', 'email' => ''],
    ['name' => 'Nick', 'email' => ''],
    ['name' => 'Holly', 'email' => ''],

foreach ($users as $user)

Here's the example with model factories:

factory(App\User::class, 3)->create();

Much easier!

Chris Sevilleja

156 posts

Co-founder of Slapping the keyboard until something good happens.