NavTools package
1 - From the command line run, (*2)
composer require syscover/laravel-nav-tools
2 - Register service provider, on file config/app.php add to providers array, (*3)
Syscover\NavTools\NavToolsServiceProvider::class,
3 - To publish package, you must type on console, (*4)
php artisan vendor:publish --provider="Syscover\NavTools\NavToolsServiceProvider"
4 - Register middlewares pulsar.navTools on file app/Http/Kernel.php add to routeMiddleware array, (*5)
'pulsar.navTools' => \Syscover\NavTools\Middleware\NavTools::class,
Set url type for you web, you have three types, lang, country or lang-country, for urls type lang:, (*6)
NAVTOOLS_URL_TYPE=lang
you can work with this urls, (*7)
hrrp://mydomain.com/en/any-page
for urls type country, (*8)
NAVTOOLS_URL_TYPE=country
you can work with this urls, (*9)
hrrp://mydomain.com/us/any-page
for urls type lang-country, (*10)
NAVTOOLS_URL_TYPE=lang-country
you can work with this urls, (*11)
hrrp://mydomain.com/en-us/any-page
Set countries available in your web, (*12)
NAVTOOLS_LANGS=en|es
Set countries available in your web, (*13)
NAVTOOLS_COUNTRIES=us|gb|es
Set default country for your web, (*14)
NAVTOOLS_DEFAULT_COUNTRY=es
On app\Http\routes.php file use this closure to implement routes with translation, (*15)
Route::group(['middleware' => ['pulsar.navTools']], function() { // write here your routes });
You have several url configuration options depends on the chosen NAVTOOLS_URL_TYPE parameter:, (*16)
Write your routes with lang variable, (*17)
Route::group(['middleware' => ['pulsar.navTools']], function() { Route::get('/', function(){ return view('www.index'); }); Route::get('{lang}', function(){ return view('www.index'); }); Route::post('{lang}/contact', ['as'=>'contact', 'uses'=>'FrontEndController@contact']); });
Or set lang variable on your routes, (*18)
Route::group(['middleware' => ['pulsar.navTools']], function() { Route::get('/', function(){ return view('www.index'); }); Route::get('en', function(){ return view('www.index'); }); Route::get('es', function(){ return view('www.index'); }); Route::post('en/contact', ['as' => 'contact-en', 'uses'=>'FrontEndController@contact']); Route::post('es/contacto', ['as' => 'contact-es', 'uses'=>'FrontEndController@contact']); });
Or set constant lang but country variable, (*19)
Route::group(['middleware' => ['pulsar.navTools']], function() { Route::get('/', function(){ return view('www.index'); }); Route::get('/en-{country}', function(){ return view('www.index'); }); Route::get('/es-{country}', function(){ return view('www.index'); }); Route::post('en-{country}'/contact', ['as' => 'contact-en', 'uses'=>'FrontEndController@contact']); Route::post('es-{country}'/contacto', ['as' => 'contact-es', 'uses'=>'FrontEndController@contact']); });
Or use lang and country variables to get language value., (*20)
Route::group(['middleware' => ['pulsar.navTools']], function() { Route::get('/', function(){ return view('www.index'); }); Route::get('/{lang}-{country}', function(){ return view('www.index'); }); Route::post('/{lang}-{country}/contact', ['as' => 'contact-en', 'uses'=>'FrontEndController@contact']); });
You can get lang and country values with this helpers., (*21)
user_country(); // to get country user user_lang(); // to get language user
To set routes you need to add lang or country parameters depending on NAVTOOLS_URL_TYPE., (*22)
route('routeName', ['lang' => 'en', 'country' => 'us']);
You can use a custom helper nt_route(), this helper inserts automatically variables lang and country, unless you specify these variables., (*23)
nt_route('routeName');
You can use redirect() helper without any trouble, we have extended Laravel core so that redirect()->route() does the same as nt_route()., (*24)
If you want to change the language or the country you must use this helpers, (*25)
change_language('en'); change_country('us');
The NavTools is open-sourced software licensed under the MIT license., (*26)