framework icon indicating copy to clipboard operation
framework copied to clipboard

Validation $errors is empty

Open livingos opened this issue 12 years ago • 12 comments

Since recent updates $errors is always empty.

Plenty of others seeing problem: https://laracasts.com/discuss/channels/general-discussion/l5-form-errors-not-showing-up

livingos avatar Oct 08 '14 20:10 livingos

Confirming this issue.

avxkim avatar Oct 09 '14 16:10 avxkim

Confirmed as well. Still exists as of the latest commit.

0xMatt avatar Oct 10 '14 04:10 0xMatt

Needs to be fixed. Can't develop / debug forms without it.

Marwelln avatar Oct 13 '14 08:10 Marwelln

Not returning any errors, had to stop working on project, waiting for fix. Any clues how long it may take?

Gibonek avatar Oct 13 '14 08:10 Gibonek

@Gibonek You can temporarily get around it by adding this to the top of your view:

<?php $errors = Session::has('errors') ? Session::get('errors') : $errors; ?>

alexleonard avatar Oct 13 '14 10:10 alexleonard

Seems to be caused by the middleware stack being run through after the app has booted. So the session isn't properly set up when the view service provider attempts to grab the errors. Looking into a fix, although Taylor will probably be better suited to fixing this. Patience folks.

jasonlewis avatar Oct 13 '14 10:10 jasonlewis

Thank you @alexleonard , I found better solution :

@if (Session::get('errors'))
  <div class="alert alert-dismissable alert-warning">
    <h4>Uwaga!</h4>
    <ul>
      @foreach (Session::get('errors')->all() as $error)
          <li>{!! $error !!}</li>
      @endforeach
    </ul>
    </div>
@endif

Now i got all in place, and working, many thanks for info that some hacks exist to go over this issue.

Sorry for bad English, i'm not native :)

Gibonek avatar Oct 13 '14 18:10 Gibonek

You can add another cheap hack:

class FormErrorsMiddleware implements Middleware {

 /**
  * Handle an incoming request.
  *
  * @param \Illuminate\Http\Request $request
  * @param \Closure $next
  * @return mixed
  */
 public function handle($request, Closure $next)
 { 
  if (\Session::has('errors')) {
   view()->share('errors', \Session::get('errors'));
  }
  return $next($request);
 }

}

and add this form error middleware to your AppServiceProvider $stack array ;)

mn7z avatar Oct 13 '14 19:10 mn7z

Should be fixed with latest commits. Added new View\ErrorBinder middleware to stack so you'll want to add that to your stack.

taylorotwell avatar Oct 14 '14 03:10 taylorotwell

It looks like there are still issues, since PHPUnit appears to be skipping Middleware:

1) App\Tests\Controller\AuthTest::testLoginPageLoads
ErrorException: Undefined variable: errors (View: /home/valorin/workspace/app/resources/views/auth/login.blade.php)

It loads fine in the browser.

valorin avatar Oct 14 '14 21:10 valorin

@valorin this looks to be fixed in 23d7b9e046244ec5ef7c2ac9eade9e1545883fd2, handle now correctly fires the middleware stack.

jasonlewis avatar Oct 15 '14 03:10 jasonlewis

Thanks :-) I can confirm it's now working as expected.

valorin avatar Oct 15 '14 10:10 valorin