Youssef Lahssini
Youssef Lahssini

Reputation: 131

Laravel 4 Redirect Header

Right now I'm trying to learn and test Laravel 4, and I have a little concern about script.

I wanted to insert information into the database, then redirect to the index page; the problem is that when I refresh the page, it displays the message to resend.

Here is the code I use:

public function store()
{
    $new_cat = new Cat;
    $new_cat->name = Input::get('new_cat');
    $new_cat->age = Input::get('age_cat');

    $new_cat->save();
    return Redirect::action('CatsController@index');

}

Upvotes: 1

Views: 3319

Answers (2)

Steven W
Steven W

Reputation: 145

The correct way to handle a POST request with a redirect is to issue a 303 status code.

http://en.wikipedia.org/wiki/HTTP_303

Using your original code:

return Redirect::action('CatsController@index', array(), 303);

Or Ochi's:

return Redirect::to('route_name', 303)->withInput();

Upvotes: 2

Ochi
Ochi

Reputation: 1478

maybe that will work

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

Upvotes: 0

Related Questions