0
0
Laravelframework~10 mins

Why database integration is core in Laravel - Test Your Understanding

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

Complete the code to connect to the default database in Laravel.

Laravel
DB::[1]('select * from users');
Drag options to blanks, or click blank then click option'
Ainsert
Bselect
Cupdate
Ddelete
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'insert' instead of 'select' to get data.
Trying to use 'update' or 'delete' when just reading data.
2fill in blank
medium

Complete the code to create a new user record using Eloquent.

Laravel
$user = new User();
$user->name = 'John';
$user->email = 'john@example.com';
$user->[1]();
Drag options to blanks, or click blank then click option'
Asave
Bdelete
Cupdate
Dfind
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'delete' instead of 'save' to add data.
Using 'find' which only retrieves data.
3fill in blank
hard

Fix the error in the query builder to get users older than 18.

Laravel
$users = DB::table('users')->where('age', '[1]', 18)->get();
Drag options to blanks, or click blank then click option'
A<
B!=
C=
D>
Attempts:
3 left
💡 Hint
Common Mistakes
Using '=' which selects only age exactly 18.
Using '<' which selects younger users.
4fill in blank
hard

Fill both blanks to update the email of a user with id 5.

Laravel
DB::table('users')->where('id', [1])->[2](['email' => 'new@example.com']);
Drag options to blanks, or click blank then click option'
A5
Bupdate
Cdelete
Dinsert
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'delete' instead of 'update' to change data.
Using wrong id value.
5fill in blank
hard

Fill all three blanks to create a dictionary of user names and emails for users older than 20.

Laravel
$users = DB::table('users')->where('age', '[1]', 20)->pluck('[2]', '[3]');
Drag options to blanks, or click blank then click option'
A>
Bemail
Cname
D<
Attempts:
3 left
💡 Hint
Common Mistakes
Using '<' instead of '>' to filter users.
Swapping name and email in pluck parameters.