Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Controller redirect back to a POST form

I have a table showing a list of names, with an "edit" button and hidden id value at the side. Clicking the "edit" button will post the hidden id as a form value and display the edit page so the user can change details of that person. Pretty standard.

When editing the details and submitting I'm using a validator. If the validation fails it needs to go back to the edit page and display the errors. Problem is that the edit page required an Id value via POST method, but the redirect only seems to utilise the GET method which leads to a "Controller Method Not Found" error as there is no Get route set up.

Does anyone know how I can redirect back to the page via POST not GET. Currently my code looks like:

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

thanks

like image 675
James Avatar asked Dec 12 '13 15:12

James


1 Answers

You can use Redirect::back()->withInput();

You may wish to redirect the user to their previous location, for example, after a form submission. You can do so by using the back method

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

like image 193
Juliano Pezzini Avatar answered Oct 03 '22 14:10

Juliano Pezzini