Challenge - 5 Problems
Tinker Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ component_behavior
intermediate1:30remaining
What is the output of this Tinker command?
You run this command in Laravel Tinker:
What does this command return if a user with that email exists?
App\Models\User::where('email', 'admin@example.com')->exists();What does this command return if a user with that email exists?
Attempts:
2 left
💡 Hint
Think about what the 'exists()' method returns in Laravel queries.
✗ Incorrect
The 'exists()' method returns a boolean true if any record matches the query, otherwise false.
📝 Syntax
intermediate1:30remaining
Which Tinker command correctly updates a user's name?
You want to update the name of the user with id 5 to 'Alice' using Laravel Tinker. Which command is correct?
Attempts:
2 left
💡 Hint
Remember how to update attributes and save changes in Eloquent models.
✗ Incorrect
Option B uses the correct update method on the model instance. Option B has wrong syntax for update. Options C and D misuse save/update methods.
🔧 Debug
advanced2:00remaining
Why does this Tinker command cause an error?
You run:
But the email does not update in the database. Why?
$user = App\Models\User::find(10); $user->email = 'new@example.com';But the email does not update in the database. Why?
Attempts:
2 left
💡 Hint
Think about how Eloquent saves changes to the database.
✗ Incorrect
Changing attributes on a model instance in Tinker does not save to the database until you call save().
❓ state_output
advanced1:30remaining
What is the output of this Tinker code?
Run this in Laravel Tinker:
What does it output?
$count = App\Models\Post::where('published', true)->count(); echo $count;What does it output?
Attempts:
2 left
💡 Hint
The count() method returns a number, not a boolean or array.
✗ Incorrect
The count() method returns the total number of records matching the query.
🧠 Conceptual
expert2:30remaining
Which Tinker command will delete all users created before 2020 safely?
You want to delete all users created before 2020 using Laravel Tinker. Which command is the best to avoid accidental mass deletion?
Attempts:
2 left
💡 Hint
Consider which method deletes only the targeted records safely.
✗ Incorrect
Option A deletes only users created before 2020. Option A deletes all users. Option A tries to delete on a collection, which fails. Option A deletes all records in the table.