Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

artisticre's avatar

Single Page Design & Laravel Form

I have a simple form on a one page design. I have it displaying but I am not sure how to reroute it back to the contact form after sbumition. Below is my contactcontroller.

public function store(Request $request)
  {

    $contact = [];

      $contact['firstname'] = $request->get('firstname');
      $contact['lastname'] = $request->get('lastname');
      $contact['email'] = $request->get('email');
      $contact['phone'] = $request->get('phone');
      $contact['msg'] =  $request->get('msg');

      flash('Your Message Has Been Sent!  Someone Will Contact You Soon!')->success();
      return redirect()->url('This is my question');
    }
0 likes
7 replies
Snapey's avatar

return back();

or

return redirect(route('contact.form')); ... or whatever you name the route

eg

Route::get('/contact','ContactController@show')->name('contact.form');
artisticre's avatar

Would I change my routes from

Route::get('contact', 'ContactController@create')->name('contact.create');
Route::post('contact', 'ContactController@store')->name('contact.store');

to

Route::get('#contact', 'ContactController@create')->name('contact.create');
Route::post('#contact', 'ContactController@store')->name('contact.store');
Snapey's avatar

Why would you change the route? What route are you using to show the page?

It still has a route even if it is an SPA

How are you changing the URL when switching pages in the front-end?

artisticre's avatar

in my navbar I have an anchor #contact. I want it to go back to that section once submitted

Snapey's avatar

so if it is /#contact then just put that in the redirect

return redirect('/#contact');

Please or to participate in this conversation.