Dev
Dev

Reputation: 1073

Why does not work withErrors in Laravel?

I use withErrors() to pass validation messages in template blade:

if ($validator->fails()) {
            dd($validator); // Gives me filled array with messages
            return Redirect::back()
                ->withErrors($validator)
                ->withInput();

In template I have:

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

I am guess that problem in the call stack of templates blade, or in function withErrors.

If withErrors uses session, maybe this is one of problem.

Additionally this is my call validation:

$validator = Validator::make($request->all(), [
            "name" => 'required|string|min:10',
            "text" => 'required|string|min:10',
        ]);

Upvotes: 0

Views: 2501

Answers (1)

Calin Blaga
Calin Blaga

Reputation: 1373

Try this in view:

@if(Session::has('error'))
    {{ Session::get('error') }}
@endif

Upvotes: 1

Related Questions