Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to check if there are any validation errors.
Laravel
@if ($errors->[1]()) <div class="alert alert-danger"> <ul> @foreach ($errors->all() as $error) <li>{{ $error }}</li> @endforeach </ul> </div> @endif
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using a method name that does not exist on the $errors object.
Forgetting the parentheses after the method name.
✗ Incorrect
The method 'any()' checks if there are any validation errors present.
2fill in blank
mediumComplete the code to display each validation error inside a list item.
Laravel
@foreach ($errors->[1]() as $error) <li>{{ $error }}</li> @endforeach
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using a method that does not return an array of errors.
Using a property instead of a method.
✗ Incorrect
The 'all()' method returns all validation error messages as an array.
3fill in blank
hardFix the error in the code to correctly display the first validation error for the 'email' field.
Laravel
@if ($errors->has('[1]')) <span class="text-danger">{{ $errors->first('[1]') }}</span> @endif
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using a different or incorrect field name.
Forgetting to use quotes around the field name.
✗ Incorrect
The validation error key must match the input field name, which is usually 'email'.
4fill in blank
hardFill both blanks to create a Blade directive that shows all errors for the 'password' field inside a div.
Laravel
@if ($errors->[1]('[2]')) <div class="error-messages"> @foreach ($errors->get('[2]') as $message) <p>{{ $message }}</p> @endforeach </div> @endif
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'any' instead of 'has' for a specific field.
Using the wrong field name.
✗ Incorrect
The 'has' method checks if errors exist for a specific field, here 'password'.
5fill in blank
hardFill all three blanks to create a Blade snippet that displays the first error for the 'username' field inside a span with a class.
Laravel
@if ($errors->[1]('[2]')) <span class="[3]">{{ $errors->first('[2]') }}</span> @endif
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'any' instead of 'has' for specific field check.
Using wrong field name or CSS class.
✗ Incorrect
Use 'has' to check errors for 'username' and 'text-danger' for styling the error message.