0
0
Laravelframework~10 mins

Why Query Builder offers flexibility in Laravel - Test Your Understanding

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to start a query using Laravel's Query Builder.

Laravel
$users = DB::[1]('users')->get();
Drag options to blanks, or click blank then click option'
Aselect
Btable
Cfrom
Dquery
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'select' instead of 'table' to start the query.
2fill in blank
medium

Complete the code to add a condition to the query.

Laravel
$users = DB::table('users')->where('[1]', 'active')->get();
Drag options to blanks, or click blank then click option'
Aid
Bname
Cemail
Dstatus
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'name' or 'email' which are not status indicators.
3fill in blank
hard

Fix the error in the code to chain multiple conditions.

Laravel
$users = DB::table('users')->where('status', 'active')->[1]('age', '>', 18)->get();
Drag options to blanks, or click blank then click option'
AorWhere
BwhereBetween
Cwhere
Dhaving
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'orWhere' changes the logic to OR instead of AND.
4fill in blank
hard

Fill both blanks to select specific columns and order results.

Laravel
$users = DB::table('users')->[1](['name', 'email'])->orderBy('[2]', 'desc')->get();
Drag options to blanks, or click blank then click option'
Aselect
Bwhere
Ccreated_at
Dname
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'where' instead of 'select' for columns.
5fill in blank
hard

Fill all three blanks to group results, count users, and filter groups.

Laravel
$results = DB::table('users')->select('[1]', DB::raw('[2] as user_count'))->groupBy('[3]')->having('user_count', '>', 5)->get();
Drag options to blanks, or click blank then click option'
Astatus
Bcount(*)
Dage
Attempts:
3 left
💡 Hint
Common Mistakes
Using different columns for select and groupBy.