Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to count all users in the database.
Laravel
$count = User::[1](); Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using sum() instead of count()
Using avg() which calculates average
✗ Incorrect
The count() method returns the total number of records.
2fill in blank
mediumComplete the code to get the total price of all orders.
Laravel
$total = Order::[1]('price');
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using count() which counts rows
Using avg() which calculates average
✗ Incorrect
The sum('price') method adds all values in the price column.
3fill in blank
hardFix the error in the code to calculate the average age of users.
Laravel
$averageAge = User::[1]('age');
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using sum() or count() instead of avg()
✗ Incorrect
The avg('age') method calculates the average value of the age column.
4fill in blank
hardFill both blanks to count users older than 30.
Laravel
$count = User::where('age', [1], [2])->count();
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '<' instead of '>'
Using wrong number like 25
✗ Incorrect
The where('age', '>', 30) filters users older than 30, then count() counts them.
5fill in blank
hardFill all three blanks to get the average price of products cheaper than 100.
Laravel
$average = Product::where('price', [1], [2])->[3]('price');
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '>' instead of '<'
Using sum() instead of avg()
✗ Incorrect
The code filters products with price less than 100, then calculates the average price.