Support the ongoing development of → Requests Forms
Last updated 2 years ago.

Hi Douglas,

I'm not sure why you are adding an extra step to the user after posting the data, sending him to "pages.preview_ad" and then adding a "Go Back" link. In my opinion it is an unnecessary step but don't know the whole logic of your app so don't judge.

  1. You could reduce the first four lines of the store method by replacing them with:
$previewData = Preview::create(["title"=>$request->title]);

That's gonna save and return the data you need.

  1. If you need to keep the logic you're currently using just add this to the go_back method in your controller
$previewData = Preview::latest('id')->first();  
return view('the previous view')->with('previewData', $previewData);

Alternatively you could add the id of your actual preview to the link(in the view) and use it as a variable to find the right Preview when going back, you would need to change your route to:

Route::get('/Create_ad/go_back/{id}', 'PreviewsController@go_back');

and go_back method to:

public function go_back($id=null)
   $previewData = Preview::find($id);
   return view('your preview view')->with($previewData);

You also need to make sure your checking if previewData is not empty on the view and then filling each input. Take a look at Form::Model if you have a chance, it'd be very useful for this matter.

Last updated 6 years ago.

That isn't quite what i mean, i want to go back to the page before the preview (only if my link is used), where the form is posted. On that page i want to have all inputs to be filled in as before the form was submitted. It works if i run the line of code here inside the store method, but not when i run it in "go_back" method.

return back()->withInput();
Last updated 6 years ago.

Sign in to participate in this thread!


Your banner here too?


We'd like to thank these amazing companies for supporting us

Your logo here?

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 - All rights reserved.