Skip to content

Commit

Permalink
[5.x] Fix localized error messages on forms when previous URL is inco…
Browse files Browse the repository at this point in the history
…rrect (#11219)
  • Loading branch information
jasonvarga authored Dec 5, 2024
1 parent a0a385a commit 278ca3c
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/Http/Requests/FrontendFormRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,15 @@ public function validateResolved()
// If this was submitted from a front-end form, we want to use the appropriate language
// for the translation messages. If there's no previous url, it was likely submitted
// directly in a headless format. In that case, we'll just use the default lang.
$site = ($previousUrl = session()->previousUrl()) ? Site::findByUrl($previousUrl) : null;
$site = ($previousUrl = $this->previousUrl()) ? Site::findByUrl($previousUrl) : null;

return $this->withLocale($site?->lang(), fn () => parent::validateResolved());
}

private function previousUrl()
{
return ($referrer = request()->header('referer'))
? url()->to($referrer)
: session()->previousUrl();
}
}

0 comments on commit 278ca3c

Please sign in to comment.