'How to I get query strings of previous URL?

I am trying to get a query strings from previous URL in Laravel. My app is similar to Formspree where users can submit a form using and it get send to my website through POST method.

Here is a form hosted on external website

<!-- https://user-website.com/?ref=53saf2 -->

<form action="https://localhost:8080/s/FORM_KEY" method="POST">
   <input type="email" name="email">
   <button type="submit">Send</button>
</form>

I want to get capture ?ref=53saf2 in my Laravel controller.

I've tried

$request->headers->get('referer');

URL::previous();

$_SERVER['HTTP_REFERER'];

None of it can capture ?ref.

My API route is

Route::post('s/{FORM_KEY}', [Controllers\SubmissionController::class, 'processForm']);


Solution 1:[1]

Store query string in service provider in a session

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Subhan Shamsoddini