0
0
Laravelframework~10 mins

Seeding data in Laravel - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to run all seeders in Laravel.

Laravel
php artisan [1]
Drag options to blanks, or click blank then click option'
Adb:seed
Bmigrate
Cmake:seeder
Dcache:clear
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'migrate' instead of 'db:seed' runs migrations, not seeders.
Using 'make:seeder' creates a seeder file but does not run it.
2fill in blank
medium

Complete the code to create a new seeder class named UserSeeder.

Laravel
php artisan [1] UserSeeder
Drag options to blanks, or click blank then click option'
Adb:seed
Bmake:seeder
Cmigrate
Droute:list
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'db:seed' runs seeders but does not create files.
Using 'migrate' runs migrations, unrelated to seeder creation.
3fill in blank
hard

Fix the error in the run method to insert a user with name 'Alice'.

Laravel
public function run()
{
    DB::table('users')->[1]([
        'name' => 'Alice',
        'email' => 'alice@example.com',
        'password' => bcrypt('password')
    ]);
}
Drag options to blanks, or click blank then click option'
Aupdate
Bselect
Cdelete
Dinsert
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'update' tries to change existing records but no condition is given.
Using 'delete' or 'select' does not add data.
4fill in blank
hard

Fill both blanks to call the UserSeeder from DatabaseSeeder.

Laravel
public function run()
{
    $this->[1](UserSeeder::[2]);
}
Drag options to blanks, or click blank then click option'
Acall
Bclass
Cexecute
Dstart
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'execute' or 'start' are not Laravel seeder methods.
Calling UserSeeder without '::class' will cause errors.
5fill in blank
hard

Fill all three blanks to create a factory-based seeder for 10 users.

Laravel
public function run()
{
    User::[1]([2])->[3]();
}
Drag options to blanks, or click blank then click option'
Afactory
B10
Ccreate
Dmake
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'make' instead of 'create' will not save users to the database.
Omitting the number will create only one user.