Generating Database Seeders

Blueprint also supports defining a seeders section within a draft file to generate database seeders for a given model.

The syntax for this section is simply seeders: value, where value is a comma separated list of model references.

For example:

    title: string:400
    content: longtext
    published_at: nullable timestamp

    post_id: id
    content: longtext
    user_id: id

    name: string

seeders: Post, Comment

From this definition, Blueprint will create two seeders: PostSeeder and CommentSeeder, respectively.

Notice Blueprint does not create a UserSeeder in this instance since it was not included in the list of model references.

The code within the generated seeder uses the model factories to seed the database with 5 records.

For example, within the PostSeeder, Blueprint would generate the following code:

public function run()
    factory(\App\Post::class, 5)->create();