Elmasry
Elmasry

Reputation: 53

Undefined offset: 0 when using ->with_input() - laravel

I'm getting this error when using with_input() to keep the user old input data after submiting with validation errors:

ErrorException Undefined offset: 0

the code for redirect is:

return Redirect::to('login')->with_input();

Upvotes: 0

Views: 4611

Answers (2)

Glad To Help
Glad To Help

Reputation: 5387

I am not sure which version of Laravel you are using, but your code should be:

return Redirect::to('login')->withInput();

and if you are returning errors too, you might consider using withErrors() in addition:

Route::post('register', function()
{
    $rules = array(...);

    $validator = Validator::make(Input::all(), $rules);

    if ($validator->fails())
    {
        return Redirect::to('register')->withErrors($validator);
    }
});

Check the docs: http://laravel.com/docs/validation#error-messages-and-views

Upvotes: 2

duellsy
duellsy

Reputation: 8595

If you're using Laravel 4, you need to use withInput instead of with_input

Upvotes: 1

Related Questions