Reputation: 131
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
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