In some cases, you will need a set of if (or switch ) switch , since you have to make a decision.
I would not rely on the referrer URL, as it will break if you ever change your routes. Like you, I prefer route names for everything, as my URLs can change.
How about a session key? Set some value, then extract it and select the redirection after creating the company. Something like that:
In the controller method for creating company page # 1
Session::put('create-company-method', 1);
Then, after creating the company
$flag = Session::get('create-company-method'); if ($flag===1) { return redirect()->route('go-here-next'); } else if ($flag===2) { ... }
It is ugly, but it will be a trick. Plus it has a big advantage: you can make the session values ββthe way you want, so if you need to add additional information to make a decision, go ahead. Do you need wildcards? Set the session key, however you want to pass this information.
source share