So I have implemented language switching for my application, across majority of the pages it works well, however there is one page where switching language returns 404. When I switch language, route looks like this e.g. password/lang/en followed by 404 error, but if I remove password from the url tab then I get redirected with back with language being switched.
My translations are placed in resources/lang/language_name
Route for switching language:
Route::get('lang/{locale}', 'Localization\LocalizationController@index');
Route where 404 is thrown when switch(this is from Laravel's auth layer):
$this->get('password/reset', 'Auth\ForgotPasswordController@showLinkRequestForm');
Controller:
public function index($locale)
{
App::setLocale($locale);
//storing the locale in session to get it back in the middleware
session()->put('locale', $locale);
return redirect()->back();
}
Middleware/Localization.php:
public function handle($request, Closure $next)
{
if (session()->has('locale')) {
App::setLocale(session()->get('locale'));
}
return $next($request);
}
I have no idea where to look at and wasn't being able to find that anyone has encountered this problem.
EDIT If I add password to switching route:
Route::get('password/lang/{locale}', 'Localization\LocalizationController@index');
It works then, but obviously other routes wouldn't, my question would be do I leave it like this, 2 separate routes:
Route::get('/lang/{locale}', 'Localization\LocalizationController@index');
Route::get('password/lang/{locale}', 'Localization\LocalizationController@index');
or there is a better option here?