i added localization and use routes like:
Route::get('/', function () {
return redirect('/en/home');
});
Route::group(
[
'prefix' => App\Libraries\myLocalization::getLocale(),
],
function() {
Route::get('/home', 'HomeController@getHome')->name('home');
Route::group(
[
'prefix' => 'admin',
'middleware' => [
'auth',
],
],
function() {
Route::get('/', 'AdminController@getHome')->name('admin.home');
Route::resource('/users', '\App\Http\Controllers\UserController');
Route::resource('/roles', 'RoleController');
Route::resource('/permissions', 'PermissionController');
}
);
}
);
in getLocale i simply check if there is a preference (cookie/session/db) and if not locale gets set to requested locale (app()->request->segment(1)).
this works all fine but i noticed that calling such routes by name doesnt work any more.
i fear that my solution has the trade off that using route names just isnt possible anymore which is too bad.
but perhaps there is another way still?
i could just drop the segment detection to determine language and use a middleware to set locale but that has a downside that linking to an url in a certain language will result in a default language page.
eg:
http://mysite.com/en/some-awesome-article
will give desired result
http://mysite.com/some-awesome-article
will redirected to that same page in the default language... since it cannot know what the original language was. and perhaps the article isnt even available in the default language.
another option could be something like:
Route::get('/', 'AdminController@getHome')->name(App\Libraries\myLocalization::getLocale() . '.admin.home');
but that feels eeeww...
any thoughts?