Skip to content

Instantly share code, notes, and snippets.

@MuhamedPy
Last active January 25, 2020 22:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MuhamedPy/fb9676a839e7ca34ca1188ede6323af3 to your computer and use it in GitHub Desktop.
Save MuhamedPy/fb9676a839e7ca34ca1188ede6323af3 to your computer and use it in GitHub Desktop.
if (app()->getLocale() == 'ar'){
\LaravelLocalization::setLocale('en');
}else{
\LaravelLocalization::setLocale('ar');
}
$UrlPrevious = url()->previous();
if(strpos(url()->previous(), '/p/') !== false){
$UrlProduct= ltrim(strstr(url()->previous(),"/p/"),"/p/");
$previousLang = request()->segment(1) ;
$slug = Product::where("slug_$previousLang",$UrlProduct)
->first()
->slug;
$UrlPrevious = str_replace($UrlProduct,$slug,$UrlPrevious) ;
}elseif (strpos(url()->previous(), '/s/') !== false || strpos(url()->previous(), '/f/') !== false){
if (strpos(url()->previous(), '/s/')){
$segment = '/s/';
}else{
$segment = '/f/';
}
$UrlProduct= ltrim(strstr(url()->previous(),$segment),$segment);
$oldSlug = str_replace(strstr($UrlProduct,'?'),'',$UrlProduct) ;
$previousLang = request()->segment(1);
$slug = SubCategory::where("slug_$previousLang",$oldSlug)
->first()
->slug;
$UrlPrevious = str_replace($oldSlug,$slug,$UrlPrevious) ;
}
$url = \LaravelLocalization::getLocalizedURL(App::getLocale(), $UrlPrevious);
return redirect($url);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment