Challenge - 5 Problems
Laravel Validation Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate2:00remaining
What does the 'required' validation rule do in Laravel?
In Laravel, what is the behavior of the 'required' validation rule when applied to a form input?
Attempts:
2 left
💡 Hint
Think about whether the field can be left blank or missing.
✗ Incorrect
The 'required' rule makes sure the input is present in the request and is not empty. If missing or empty, validation fails.
❓ component_behavior
intermediate2:00remaining
What output does this Laravel validation produce?
Given this validation rule in a Laravel controller:
What happens if the input 'age' is '17'?
$request->validate(['age' => 'integer|min:18']);
What happens if the input 'age' is '17'?
Attempts:
2 left
💡 Hint
Check what the 'min:18' rule means for integers.
✗ Incorrect
The 'min:18' rule requires the integer to be at least 18. Since 17 is less, validation fails.
📝 Syntax
advanced2:00remaining
Which validation rule syntax is correct for checking a valid email in Laravel?
Select the correct syntax to validate that an input named 'email' is a valid email address in Laravel.
Attempts:
2 left
💡 Hint
Order matters for readability but not for correctness; check rule names carefully.
✗ Incorrect
The correct rule names are 'required' and 'email'. 'email_address' is invalid and 'numeric' conflicts with email.
🔧 Debug
advanced2:00remaining
Why does this Laravel validation rule cause an error?
Consider this validation rule:
Why will this cause a validation error?
'username' => 'required|min:3|max'
Why will this cause a validation error?
Attempts:
2 left
💡 Hint
Check if all rules have required parameters.
✗ Incorrect
The 'max' rule requires a value like 'max:10'. Without it, Laravel throws an error.
❓ state_output
expert2:00remaining
What is the validation result for this Laravel rule with input 'tags'?
Given this validation rule:
And the input:
What is the validation result?
'tags' => 'array|min:2'
And the input:
tags = ['php']
What is the validation result?
Attempts:
2 left
💡 Hint
Consider how 'min' works with arrays in Laravel validation.
✗ Incorrect
The 'min:2' rule requires the array to have at least 2 items. Since 'tags' has only 1, validation fails.