Laravel / Views / Form with errors and old values
Form with errors and old values
-
Steps
1. Show validation error
Laravel controller$request->validate([ 'title' => 'required|unique:posts|max:255', 'body' => 'required', ]); if($validate->fails()) { return Redirect::back()->withErrors($validate); } 2. show old form values and default form values
In controller
In viewif($validate->fails()) { return Redirect::back()->withInput()->withErrors($validate); } @if (count($errors) > 0) -
@foreach ($errors->all() as $error)
- {{ $error }} @endforeach