0
0
Laravelframework~10 mins

Tinker for database interaction 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 start Laravel Tinker from the command line.

Laravel
php artisan [1]
Drag options to blanks, or click blank then click option'
Amake:model
Bserve
Cmigrate
Dtinker
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'serve' instead of 'tinker' starts the web server, not the shell.
Using 'migrate' runs database migrations, not the shell.
2fill in blank
medium

Complete the code to retrieve all records from the User model in Tinker.

Laravel
App\Models\User::[1]();
Drag options to blanks, or click blank then click option'
Afind
Bget
Call
Dfirst
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'find' requires an ID parameter and returns one record.
Using 'first' returns only the first record.
3fill in blank
hard

Fix the error in the code to find a user by ID 5 in Tinker.

Laravel
App\Models\User::[1](5);
Drag options to blanks, or click blank then click option'
Aall
Bfind
Cget
Dfirst
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'get' returns a collection, not a single record.
Using 'all' returns all records, ignoring the ID.
4fill in blank
hard

Fill both blanks to create a new user with name 'Alice' and save it in Tinker.

Laravel
$user = new App\Models\User();
$user->name = '[1]';
$user->[2]();
Drag options to blanks, or click blank then click option'
AAlice
Bsave
Ccreate
Dupdate
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'create' as a method on the instance instead of 'save'.
Forgetting to call any method to save the user.
5fill in blank
hard

Fill all three blanks to update the email of user with ID 3 to 'new@example.com' in Tinker.

Laravel
$user = App\Models\User::[1](3);
$user->[2] = '[3]';
$user->save();
Drag options to blanks, or click blank then click option'
Afind
Bemail
Cnew@example.com
Dfirst
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'first' instead of 'find' to get user by ID.
Not assigning the new email string correctly.