Laravel - 重定向回位置

So in my footer I have a form for adding subscribers to a newsletter. When you enter your email and submit the form, you get redirected back with a message. Everything works fine. However the footer is at the bottom of the page and I get redirected back to the top. Is there a way to redirect and go to the footer directly? Here is the code in my controller:

public function addSubscriber(Request $request)
{
   $this->validate($request, [
       'email' => 'required|email'
   ]);

   ...code...

   return redirect()->back()->with(['added' => $message]);
}

How can I achieve that?

Instead of doing back(), you could try something like this:

return redirect(url()->previous().'#subscribe');

Here url()->previous() will generate URL of previous page. So, you'll just need to add #subscribe which will scroll page down to an anchor. So no JS required.

Of course, you'll need to add a HTML anchor:

<a name="subscribe">Subscribe</a>

There are two ways to do this:

  1. Make a url like https://laravel.com/docs/5.1/queries#introduction, and manage the scrolling of web page by #introduction. Demo
  2. On success of message call a js function that scroll down your web page to certain pixel of height so that your footer is visible.