jeudi 23 novembre 2017

Use return back()->withInput(); after a new view is returned with a link

I am trying to first post my form to my method that returns a view to preview the post that has been done. When you get to the new view of the preview i want to be able to use a link to go back to the previous page with all form inputs already filled in.

I have tried doing this with setting another url and route to the link where the route triggers a method in my controller with the return back() call. This does not seem to work and i guess it is because it is outside my method with the $request.

So i am wondering how it would be possible to achieve what i want to do. Im using Laravel 5.5

Here is my current code:

After the form is posted, you are sent to this method:

 public function store(Request $request)
{
    $preview = new Preview();
    $preview->post_title = $request->title;
    $preview->save();
    $previewData = Preview::latest('id')->first();
    return view('pages.preview_ad')->with('previewData', $previewData);
}

In the 'preview_ad' view, i want to have a link that routes to another method that triggers

return back()->withInput();

Although when i try to do this with the code below, it does not return the previous page with the inputs which the code above should. It works properly if i run it inside the 'store' method above, but not in the other method.

Route::get('/Skapa-annons/Tillbaka', 'PreviewsController@go_back');

-

public function go_back()
{
    return back()->withInput();
}



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2B5kb6y
via IFTTT

Aucun commentaire:

Enregistrer un commentaire