0
0
Laravelframework~10 mins

Custom error messages 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 define a custom error message for the 'email' field in Laravel validation.

Laravel
$request->validate(['email' => 'required|email'], ['email.[1]' => 'Please enter a valid email address.']);
Drag options to blanks, or click blank then click option'
Aemail
Brequired
Cemail.required
Demail.email
Attempts:
3 left
💡 Hint
Common Mistakes
Using only the field name without the rule.
Using the rule name without the field.
Mixing the order like 'required.email'.
2fill in blank
medium

Complete the code to add a custom error message for the 'password' field's minimum length rule.

Laravel
$request->validate(['password' => 'required|min:8'], ['password.[1]' => 'Password must be at least 8 characters.']);
Drag options to blanks, or click blank then click option'
Amin
Bmin:8
Crequired
Dpassword.min
Attempts:
3 left
💡 Hint
Common Mistakes
Including parameters like ':8' in the key.
Using the full rule string 'min:8' as the key.
Using the field name twice.
3fill in blank
hard

Fix the error in the custom messages array to correctly target the 'username' field's 'unique' rule.

Laravel
$messages = ['username[1]unique' => 'This username is already taken.'];
Drag options to blanks, or click blank then click option'
A.
B->
C:
D-
Attempts:
3 left
💡 Hint
Common Mistakes
Using arrows or colons instead of a dot.
Concatenating without any separator.
Using dashes which are invalid here.
4fill in blank
hard

Complete the code to create a custom message for the 'age' field's 'between' rule with parameters 18 and 65.

Laravel
$messages = ['age[1]between:18,65' => 'Age must be between 18 and 65.'];
Drag options to blanks, or click blank then click option'
A.
B:
C,
D-
Attempts:
3 left
💡 Hint
Common Mistakes
Using commas instead of colons for parameters.
Missing the dot between field and rule.
Using dashes which are not valid separators here.
5fill in blank
hard

Fill all three blanks to define custom messages for a form with fields 'title' and 'content' using Laravel's validate method.

Laravel
$request->validate(['title' => 'required|max:255', 'content' => 'required'], ['title[1]required' => 'Title is needed.', 'title[2]max' => 'Title is too long.', 'content[3]required' => 'Content cannot be empty.']);
Drag options to blanks, or click blank then click option'
A.
B:
Crequired
Dmax
Attempts:
3 left
💡 Hint
Common Mistakes
Using colons or other symbols instead of dots.
Including parameters in the keys.
Mixing different separators in the same array.