0

I am learning Laravel. I am doing Form Validation at the moment. In the documentation it is said the variable $errors is flashed to the session and is always available. I get an exception because an undefined variable. I only pasted the sample code from the documentation:

@if (count($errors) > 0)
    <div class="alert alert-danger">
        <ul>
            @foreach ($errors->all() as $error)
                <li>{{ $error }}</li>
            @endforeach
        </ul>
    </div>
@endif

Error message:

ErrorException in 318c473e4384f7c25db0019a770ee937b30041d1.php line 41: Undefined variable: errors (View: C:\xampp\htdocs\NightClubs\resources\views\add.blade.php)

This are the validation rules in the controller:

$this->validate($request, [
        'youtube' => 'required|url',
        'coordinatex' => 'required|between:-180,180',
        'coordinatey' => 'required|between:-90,90',
        'nameofclub' => 'required'
]);
1
  • Please post full error message you get. Commented Mar 9, 2016 at 14:42

2 Answers 2

1

Try to use the group for routes where you want to use $errors variable:

Route::group(['middleware' => ['web']], function () {
    // Your routes
    // Your routes
}
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you, your answer has helped me.
0

I assume you have validation rules in your controller.

Try this in your view

@if ($errors->any())
    <div class="alert alert-danger">
        <ul>
            @foreach ($errors->all() as $error)
                <li>{{ $error }}</li>
            @endforeach
        </ul>
    </div>
@endif

1 Comment

Your suggestion doesn't work, as I have already said the variable is not defined. Yes, I do have validation rules in my controller, I have since added them to my question.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.