0
0
Laravelframework~10 mins

Where clauses 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 a simple where clause filtering users by 'active' status.

Laravel
$users = DB::table('users')->where('status', [1])->get();
Drag options to blanks, or click blank then click option'
A'active'
B'inactive'
C'pending'
D'deleted'
Attempts:
3 left
💡 Hint
Common Mistakes
Forgetting quotes around the status value.
Using a wrong status string.
2fill in blank
medium

Complete the code to filter users whose age is greater than 18 using a where clause.

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 '=' instead of '>' causes filtering only age exactly 18.
Using '<' or '<=' filters younger users.
3fill in blank
hard

Fix the error in the where clause to filter users with email ending in '@example.com'.

Laravel
$users = DB::table('users')->where('email', [1], '%@example.com')->get();
Drag options to blanks, or click blank then click option'
ALIKE
B=
CIN
DBETWEEN
Attempts:
3 left
💡 Hint
Common Mistakes
Using '=' does not support wildcards and will not match patterns.
Using 'IN' or 'BETWEEN' is not valid for this pattern.
4fill in blank
hard

Fill both blanks to filter users who are active and have age less than 30.

Laravel
$users = DB::table('users')->where('status', [1], 'active')->where('age', [2], 30)->get();
Drag options to blanks, or click blank then click option'
A=
B>
C<
D>=
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong operators like '>' for age.
Using '!=' instead of '=' for status.
5fill in blank
hard

Fill all three blanks to filter users with name starting with 'J', age greater or equal to 21, and status not equal to 'inactive'.

Laravel
$users = DB::table('users')->where('name', [1], 'J%')->where('age', [2], 21)->where('status', [3], 'inactive')->get();
Drag options to blanks, or click blank then click option'
ALIKE
B>=
C!=
D=
Attempts:
3 left
💡 Hint
Common Mistakes
Using '=' instead of '!=' for status.
Using '<' instead of '>=' for age.
Using '=' instead of 'LIKE' for name pattern.