Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to run all seeders in Laravel.
Laravel
php artisan [1] Drag options to blanks, or click blank then click option'
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.
✗ Incorrect
Use php artisan db:seed to run all seeders and populate the database.
2fill in blank
mediumComplete 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'db:seed' runs seeders but does not create files.
Using 'migrate' runs migrations, unrelated to seeder creation.
✗ Incorrect
The command php artisan make:seeder UserSeeder creates a new seeder class file.
3fill in blank
hardFix 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'
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.
✗ Incorrect
Use insert to add new records to the database table.
4fill in blank
hardFill 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'execute' or 'start' are not Laravel seeder methods.
Calling UserSeeder without '::class' will cause errors.
✗ Incorrect
Use $this->call(UserSeeder::class) to run the UserSeeder from DatabaseSeeder.
5fill in blank
hardFill 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'
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.
✗ Incorrect
Use User::factory(10)->create(); to generate and save 10 users using factories.