I have a laravel form which submits data via a POST request to a controller like so...
public function store()
{
$result = Validator::make(request() -> all(), $this -> rules);
if ($result -> fails())
{
return back() -> withInput() -> withErrors($result);
}
}
However, when I'm redirected back, accessing input data via the 'old' helper method returns nothing, as does reading data from $errors.
I believe the session data is being lost (possibly due to a secondary redirect?).
I've checked my routes file in artisan and the web middleware is only being run once on the routes. I'm also using the database session driver.
Any ideas? I'm using Laravel 5.2.39
Lately i encounter this error and i found the solution... Instead of putting your routes inside of this
Route::group(['middleware' => ['web']], function () { });
Just remove it and it will work properly. Its like 'web' middleware is loading twice.
Use return redirect()->back()->withInput()->withErrors($result);
try this to return back the inputs with errors
$validator = Validator::make($request->all(), $rules);
if ($validator->fails()) {
// fails, then return false
return redirect()->back()->withErrors($validator->messages())->withInput($request->all());
}
Turns out the issue is related to my use of Bootstrap Validator. I still need to figure out why, but it appears to be wiping things...