I have a url like this:
http://example.com/en/search
Now I want to check the first segment of the url like
$lang = Request::segment(1);
And I want to remove the $lang segment if it matches to the certain conditions. I'm retieving the url like this
$url = Request::fullUrl();
Now I want to reconstruct the url to something like this
http://example.com/search
Please note I cannot use str_replace because it searches in all parts of the url, I just want to search and replace in the first segment.
If you just want to make a quick check, then remove the first segment and redirect the user, you could easily do e.g. like this (for Laravel 5):
$segments = Request::segments();
$first = array_shift($segments);
if (some_condition) {
return redirect()->to(implode('/', $segments));
}
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