remove part of the segment from url laravel remove part of the segment from url laravel laravel laravel

remove part of the segment from url laravel


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));}


Try something like:

$str = 'http://example.com/en/search';$part = explode('/',$str,5);if ($part[3] == 'en') {    $url = $part[0].'//'.$part[2].'/'.$part[4];} else {     $url = $str;}echo '$url:['.$url.']';  // http://example.com/search