I made a Laravel application with the language switch. that after a language change the app redirect you back after the language change on the site. the code is as follow:
public function lang($locale)
{
App::setLocale($locale);
session()->put('locale', $locale);
return redirect()->back();
}
But i got the problem if someone send the link on facebook or other social media as example www.example.com/lang/en than the application redirect me back to the facebook but not the main application.
I was searching around how to do this better but always i saw hard coded things like extra URL as example www.example.com/lang/change/en with another function.
But i think tehere should be a way to do this better with an if checking the request but actually i can check the request url but i get always the app url back and nothing more.
So my question is how can i made so that if someone enter te url from other site than the application is will redirect me to the www.example.com/ (With the langage from the sended request like www.example.com/lang/en and not back to the facebook or like that) and when it happens on the application site will return me back to the previuse site where i was like www.example.com/post/3
I'm a starter after the school so do not be mad that i do not know everthing If someone can help me i would be thankfull!