i'm working on a CRM that should work on different countries
this is my first time using Laravel so i'm bit confused
my database looks like this:
Language
- id
- name
- short_name (en,ru etc)
Dictionary
- id
- label (sign_in,forgot_password etc)
- value ('Sign In','Вход' etc )
- language_id
i thought about working this way:
if user go to http://domain.com so it will redirect him by this steps:
- if the user logged in the past and has cookie with his language
- if there is no cookie get the country of the user by his IP
- if the country's language is not recognized in the Languages table redirect the user to default language that set on the config/app.php => 'locale' => 'default language'
i wonder if there is any way to do that without sending the language variable in every function in the controllers, what do i mean?
i mean that i dont wont my routes and my controllers to look like this:
Routes
Route::get('/{locale}', 'Auth\LoginController@showLoginForm');
Route::get('/{locale}/users/', 'UsersController@index');
Route::get('/{locale}/users/view/{id}', 'UsersController@viewUser');
Controllers
public function showLoginForm($locale)
{
App::setLocale($locale);
return view('auth.login');
}
...
public function index($locale)
{
App::setLocale($locale);
return view('users.index');
}
...
i want it to work in the background without me setting the language every time and setting the routes,
thank you!
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire