The controller redirects back to the POST form

I have a table showing a list of names, with an “edit” button and a hidden id value on the side. Pressing the "Edit" button will display the hidden identifier as the form value and display the edit page so that the user can change the data of this person. Pretty standard.

When editing details and presentation, I use a validator. If the check fails, she needs to return to the edit page and display the errors. The problem is that on the edit page, the identifier value was required via the POST method, but it seems that the GET method is used only for redirection, which leads to a "Controller error" error, since there is no "Get route" route setting.

Does anyone know how I can redirect back to the page via POST, not GET. Currently my code is as follows:

public function postEditsave(){
    ...
    if ($validator->fails())
    {
        return Redirect::to('admin/baserate/edit')
        ->withErrors($validator)
        ->withInput();
    }else{ 
                ...

thanks

+4
source share
4 answers

You can use Redirect :: back () → withInput ();

You can redirect the user to your previous location, for example, after submitting the form. You can do this using the inverse method.

See: http://laravel.com/docs/5.0/responses

+4
source

You do not need to use POST to go to the edit page. You can use the GET and parameter for the route, check this: http://laravel.com/docs/routing#route-parameters

GET, , POST , .

( ):

public function getEdit($id)
{
    return View::make(....);

}

public function postEdit($id)
{
    ...
    return Redirect::back()->withErrors($validator)->withInput();
}
+1

if there is a "redirect with POST", then I do not know this. I recommend that you just use flash data

Redirect::to('user/login')->with('id', 'something');
0
source

You can use Redirect::to("dashboard/user/$id")->withErrors($validator)->withInput();. You must use a double quote to traverse the parameter if there are errors with validation.

0
source

All Articles