Saiiif Saiiif - 1 month ago 9
PHP Question

Form validation is not displaying results on laravel

My form validation was not displaying errors on my

posts/create
route. I Googled the solution and found that

Route::group(['middleware' => 'web'], function() {
Route::resource('/posts','PostsController');
});


can be changed to

Route::group(['middlewareGroups' => 'web'], function() {
Route::resource('/posts','PostsController');
});


I did that and the problem is solved now. I want to ask if this is considered a good practice to change it like this?

Also if I am removing this line from my routes it is working:

Route::group(['middleware' => 'web'], function() {


Can anyone tell me what is actually happening ?

Answer

One reason can be that 'web' middleware is applying two times in your case. Laravel by default adds web Middleware in app/Providers/RoutesServiceProvider.php and agian you are adding it in your routes.php Try it by removing web middleware from your routes.php.