Home >Backend Development >PHP Tutorial >Why Aren't My Laravel 5.2 Validation Errors Showing in My Blade View?
Problem:
Validation errors fail to appear in the blade view when a user enters invalid input during a form submission.
Controller:
public function saveUser(Request $request) { $this->validate($request, [ 'name' => 'required|max:120', 'email' => 'required|email|unique:users', 'phone' => 'required|min:11|numeric', 'course_id' => 'required' ]); $user = new User(); $user->name = $request->input(['name']); $user->email = $request->input(['email']); $user->phone = $request->input(['phone']); $user->date = date('Y-m-d'); $user->completed_status = '0'; $user->course_id = $request->input(['course_id']); $user->save(); return redirect('success'); }
Blade View:
@if(count($errors) > 0) <div>
Solution:
In Laravel 5.2.27 or higher, the web middleware is now automatically applied to all routes within routes.php. Manually adding it can cause issues.
To resolve this issue, remove the web middleware from the route group in RouteServiceProvider.php:
protected function mapWebRoutes(Router $router) { $router->group([ 'namespace' => $this->namespace, // Remove the 'web' middleware ], function ($router) { require app_path('Http/routes.php'); }); }
The above is the detailed content of Why Aren't My Laravel 5.2 Validation Errors Showing in My Blade View?. For more information, please follow other related articles on the PHP Chinese website!