PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Sunday, January 2, 2022

[FIXED] Why does not work withErrors in Laravel?

 January 02, 2022     laravel, laravel-5.2     No comments   

Issue

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',
        ]);

Solution

Try this in view:

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


Answered By - Calin Blaga
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing