Support the ongoing development of Laravel.io →
posted 8 years ago
Validation
Last updated 2 years ago.
0

I finally found a fix, and I want to share it in case anyone else ends up here with the same problem.

In app\Http\Kernel.php I moved \Illuminate\Session\Middleware\StartSession::class from the 'web' $middlewareGroups to $middleware.

I have no idea why this fixed the problem, which worries me a bit. But hey... it's working.

Last updated 8 years ago.
0

well... "errors" are flashed by saving a session variable.

what I dont know is why you are flashing something on a route that is not a web route? is it an api route? and, if it is, then why not return a json with the errors?

under the web middleware group you have a lot of things that in the opinion of the framework do not make sense outside of web things. so maybe you can either add the web middleware to your route (if it has something to do with a view, or some front-endish response.

better check that else you'll then end up having to move out cookie related stuff from there, session encryption and others.

0

I will confirm that this worked for me. I was able to reproduce this in a brand new out of the box (fresh composer create laravel/laravel). The error bag was empty until I moved StartSession in kernel.php up to $middleware.

Has anybody posted this to the Laravel bug tracker? Is there a Laravel bug tracker?

Last updated 8 years ago.
0

wschuldt said:

I finally found a fix, and I want to share it in case anyone else ends up here with the same problem.

In app\Http\Kernel.php I moved \Illuminate\Session\Middleware\StartSession::class from the 'web' $middlewareGroups to $middleware.

I have no idea why this fixed the problem, which worries me a bit. But hey... it's working.

0

ohhh yesss, this solution worked me too! you saved me! Thanks for sharing the solution. ( I spent half of my day with this )

0

it's work for me

wschuldt said:

I finally found a fix, and I want to share it in case anyone else ends up here with the same problem.

In app\Http\Kernel.php I moved \Illuminate\Session\Middleware\StartSession::class from the 'web' $middlewareGroups to $middleware.

I have no idea why this fixed the problem, which worries me a bit. But hey... it's working.

0

wschuldt said:

I finally found a fix, and I want to share it in case anyone else ends up here with the same problem.

In app\Http\Kernel.php I moved \Illuminate\Session\Middleware\StartSession::class from the 'web' $middlewareGroups to $middleware.

I have no idea why this fixed the problem, which worries me a bit. But hey... it's working.

0

muzafarali said:

it's work for me

wschuldt said:

I finally found a fix, and I want to share it in case anyone else ends up here with the same problem.

In app\Http\Kernel.php I moved \Illuminate\Session\Middleware\StartSession::class from the 'web' $middlewareGroups to $middleware.

I have no idea why this fixed the problem, which worries me a bit. But hey... it's working.

0

wschuldt said:

I'm brand new to Laravel (and fairly new at PHP), and I'm loving it so far... except for one issue that's driving me up a wall.

I'm following along with Laravel From Scratch, and the problem begins on video 11 when learning about validating form input. Well, my validation is working great -- the form is rejected in accordance with the defined validation rules. Unfortunately, when I try to view the errors, they're empty. I get:

object(Illuminate\Support\ViewErrorBag)[170]
 protected 'bags' => 
   array (size=0)
     empty

I've done a lot of research on this problem, and it looks like the issue usually occurs when the routes are not wrapped in the 'web' middleware. Here's my route's code:

Route::group(['middleware' => ['web']], function () {
  Route::get('cards', 'CardsController@index');
  Route::get('cards/{card}', 'CardsController@show');
  
  Route::post('cards/{card}/notes', 'NotesController@store');
  Route::get('notes/{note}/edit', 'NotesController@edit');
  Route::patch('notes/{note}', 'NotesController@update');	
});

And here's the function where the validation occurs:

public function store(Request $request, Card $card)
{
  $this->validate($request, [
  	'body' => 'required|min:10'
  ]);
  	
  $note = new Note($request->all());
  $card->addNote($note, 1);
  	
  return back();
}

I encountered one other error earlier in the Laracast series that I managed to correct, but it may be related: In an earlier video we were instructed to remove all of our routes from the middleware wrapper so we could focus on some other components. When my routes were out of the wrapper, I still encountered an error due to not submitting the CSRF token with a form. I fixed the problem easily enough through the magic that is Google (I just added the csrf_field tag), but I don't know why this would've happened seeing as the CSRF check occurs within the 'web' middleware.

My only theory was that sessions were not working correctly, but I did manage to set a session variable and echo it on another page.

I'm totally prepared for this to be a missing semicolon, or something equally embarrassing. Thank you so much for any help!

0

kanompung99 said:

wschuldt said:

I'm brand new to Laravel (and fairly new at PHP), and I'm loving it so far... except for one issue that's driving me up a wall.

I'm following along with Laravel From Scratch, and the problem begins on video 11 when learning about validating form input. Well, my validation is working great -- the form is rejected in accordance with the defined validation rules. Unfortunately, when I try to view the errors, they're empty. I get:

object(Illuminate\Support\ViewErrorBag)[170]
 protected 'bags' => 
   array (size=0)
     empty

I've done a lot of research on this problem, and it looks like the issue usually occurs when the routes are not wrapped in the 'web' middleware. Here's my route's code:

Route::group(['middleware' => ['web']], function () {
 Route::get('cards', 'CardsController@index');
 Route::get('cards/{card}', 'CardsController@show');
 
 Route::post('cards/{card}/notes', 'NotesController@store');
 Route::get('notes/{note}/edit', 'NotesController@edit');
 Route::patch('notes/{note}', 'NotesController@update');	
});

And here's the function where the validation occurs:

public function store(Request $request, Card $card)
{
 $this->validate($request, [
 	'body' => 'required|min:10'
 ]);
 	
 $note = new Note($request->all());
 $card->addNote($note, 1);
 	
 return back();
}

I encountered one other error earlier in the Laracast series that I managed to correct, but it may be related: In an earlier video we were instructed to remove all of our routes from the middleware wrapper so we could focus on some other components. When my routes were out of the wrapper, I still encountered an error due to not submitting the CSRF token with a form. I fixed the problem easily enough through the magic that is Google (I just added the csrf_field tag), but I don't know why this would've happened seeing as the CSRF check occurs within the 'web' middleware.

My only theory was that sessions were not working correctly, but I did manage to set a session variable and echo it on another page.

I'm totally prepared for this to be a missing semicolon, or something equally embarrassing. Thank you so much for any help!

0

Sign in to participate in this thread!

Eventy

Your banner here too?

wschuldt wschuldt Joined 27 Mar 2016

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.