0
0
Laravelframework~10 mins

OrWhere and advanced conditions 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 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'
Ajoin
BorWhere
Cwhere
Dhaving
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.
2fill in blank
medium

Complete 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'
Awhere
BorWhere
Chaving
Djoin
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.
3fill in blank
hard

Fix 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'
Ahaving
BorWhere
Cwhere
Djoin
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.
4fill in blank
hard

Fill 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'
AorWhere
Bwhere
Chaving
Djoin
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.
5fill in blank
hard

Fill 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'
AorWhere
Bwhere
Djoin
Attempts:
3 left
💡 Hint
Common Mistakes
Using orWhere inside the closure changes the logic to OR incorrectly.
Using join is unrelated to WHERE conditions.