0
0
Laravelframework~10 mins

Request validation basics 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 in a Laravel controller.

Laravel
request()->validate(['email' => '[1]']);
Drag options to blanks, or click blank then click option'
A'string'
B'nullable'
C'required'
D'unique'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'nullable' instead of 'required' allows empty input.
2fill in blank
medium

Complete the code to validate that the 'age' field is an integer in Laravel.

Laravel
request()->validate(['age' => '[1]']);
Drag options to blanks, or click blank then click option'
A'integer'
B'email'
C'boolean'
D'string'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'string' allows any text, not just numbers.
3fill in blank
hard

Fix the error in the validation rule to require the 'password' field to be at least 8 characters.

Laravel
request()->validate(['password' => 'required|[1]:8']);
Drag options to blanks, or click blank then click option'
Amax
Blength
Csize
Dmin
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'max' sets a maximum length, not minimum.
4fill in blank
hard

Fill both blanks to validate that 'username' is required and unique in the 'users' table.

Laravel
request()->validate(['username' => '[1]|[2]:users']);
Drag options to blanks, or click blank then click option'
Arequired
Bemail
Cunique
Dstring
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'email' instead of 'unique' for uniqueness.
5fill in blank
hard

Fill all three blanks to validate 'title' as required, a string, and max 255 characters.

Laravel
request()->validate(['title' => '[1]|[2]|[3]:255']);
Drag options to blanks, or click blank then click option'
Anullable
Bstring
Cmax
Drequired
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'nullable' instead of 'required' allows empty input.