Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to add an OR WHERE condition to the query builder.
Laravel
$users = DB::table('users')->where('status', 'active')->[1]('age', '>', 18)->get();
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using where instead of orWhere causes the condition to be ANDed.
Using having or join is incorrect for this purpose.
✗ Incorrect
The orWhere method adds an OR condition to the query builder in Laravel.
2fill in blank
mediumComplete the code to group multiple OR WHERE conditions inside a closure.
Laravel
$users = DB::table('users')->where('status', 'active')->[1](function ($query) { $query->where('age', '>', 18)->orWhere('role', 'admin'); })->get();
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using orWhere with a closure causes syntax or logic errors.
Using having or join is unrelated to grouping WHERE conditions.
✗ Incorrect
Using where with a closure groups the conditions inside parentheses, allowing complex OR conditions.
3fill in blank
hardFix the error in the code by completing the method to add an OR WHERE with multiple conditions.
Laravel
$users = DB::table('users')->where('status', 'active')->orWhere(function ($query) { $query->[1]('age', '>', 18)->where('role', 'admin'); })->get();
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using orWhere inside the closure causes the conditions to be ORed incorrectly.
Using having or join is unrelated here.
✗ Incorrect
Inside the closure, use where to chain multiple conditions combined with AND.
4fill in blank
hardFill both blanks to create a query that selects users who are either active, or older than 18 and admins with a specific role.
Laravel
$users = DB::table('users')->where('status', 'active')->[1](function ($query) { $query->where('age', '>', 18)->[2]('role', 'admin'); })->get();
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using where instead of orWhere for the first blank changes the logic to AND.
Using orWhere inside the closure changes the condition logic incorrectly.
✗ Incorrect
Use orWhere to add the grouped OR condition, and inside the closure use where to combine conditions with AND.
5fill in blank
hardFill all three blanks to build a query that finds users who are either active, or older than 18 and admins with a specific role and verified email.
Laravel
$users = DB::table('users')->where('status', 'active')->[1](function ($query) { $query->where('age', '>', 18)->[2]('role', 'admin')->[3]('email_verified', true); })->get();
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using orWhere inside the closure changes the logic to OR incorrectly.
Using join is unrelated to WHERE conditions.
✗ Incorrect
Use orWhere to add the grouped OR condition, and inside the closure use where to combine conditions with AND for role and email verification.