Imagine you have a method in controller, like storing a new company. Also imagine we can create new company from different pages in our site. For example, I can create a company from 2-3 pages.
Depending on where I created the company I need to have different redirects. Sometimes I need to redirect back, and sometimes to other routes.
Something like:
if ($previousRoute === 'companies.index') {
return redirect()->back();
} else {
return redirect()->route('someroute');
}
I guess I can't get the route name wher user came from. If I check referrer url then in case I change route URL everything will be broken so I want to rely on route names instead. Plus, the solution having many "if-s" or a "switch" is kind of weird, it will pollute the code.
Also wildcard support is needed. Some kind of route map with redirects or something like this.
Any advice how to implement this?
Well, you can compare the previous url with the url of any route. It's not the best solution and i don't know what to do with route parameters, but it can work.
if (URL::previous() === URL::route('companies.index')) {
return redirect()->back();
} else {
return redirect()->route('someroute');
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With