Redirecting in Laravel Form Requests

  • Reading time: 1 min
  • Published 8 years ago

While Form Request Validation in Laravel 5 usually does exactly what it's supposed to do, I recently had to append a location hash to the redirect URL. Turns out that's as simple as overwriting the FormRequest's getRedirectUrl()-method:

protected function getRedirectUrl()
  $url = $this->redirector->getUrlGenerator();
  return $url->previous().'#hash';