0
0
Laravelframework~10 mins

Validate method on request 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 validate the 'email' field as required and in email format.

Laravel
$request->validate(['email' => '[1]']);
Drag options to blanks, or click blank then click option'
A'required|email'
B'nullable|email'
C'string|min:5'
D'required|numeric'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'nullable' instead of 'required'
Using 'numeric' for email field
2fill in blank
medium

Complete the code to validate that 'password' is required and has a minimum length of 8 characters.

Laravel
$request->validate(['password' => '[1]']);
Drag options to blanks, or click blank then click option'
A'required|min:8'
B'required|confirmed'
C'nullable|min:8'
D'string|max:8'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'confirmed' without confirmation field
Using 'max:8' instead of 'min:8'
3fill in blank
hard

Fix the error in the validation rule to require 'age' to be numeric and at least 18.

Laravel
$request->validate(['age' => '[1]']);
Drag options to blanks, or click blank then click option'
A'required|string|min:18'
B'nullable|numeric|min:18'
C'required|numeric|max:18'
D'required|integer|min:18'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'string' for numeric field
Using 'max:18' instead of 'min:18'
4fill in blank
hard

Fill both blanks to validate 'username' as required and unique in 'users' table, and 'email' as required and email format.

Laravel
$request->validate(['username' => '[1]', 'email' => '[2]']);
Drag options to blanks, or click blank then click option'
A'required|unique:users,username'
B'required|email'
C'nullable|unique:users,email'
D'required|string|min:3'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'nullable' for required fields
Mixing up unique columns
5fill in blank
hard

Fill all three blanks to validate 'title' as required string, 'content' as required string with minimum 10 characters, and 'published' as boolean.

Laravel
$request->validate(['title' => '[1]', 'content' => '[2]', 'published' => '[3]']);
Drag options to blanks, or click blank then click option'
A'required|string'
B'required|string|min:10'
C'boolean'
D'nullable|string'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'nullable' instead of 'required'
Missing 'min:10' for content