Package Data | |
---|---|
Maintainer Username: | carlospalacin |
Maintainer Contact: | info@syscover.com (SYSCOVER SL) |
Package Create Date: | 2017-04-21 |
Package Last Update: | 2018-09-13 |
Language: | PHP |
License: | MIT |
Last Refreshed: | 2025-01-25 15:05:03 |
Package Statistics | |
---|---|
Total Downloads: | 246 |
Monthly Downloads: | 0 |
Daily Downloads: | 0 |
Total Stars: | 0 |
Total Watchers: | 3 |
Total Forks: | 0 |
Total Open Issues: | 0 |
1 - From the command line run
composer require syscover/pulsar-navtools
2 - To publish package, you must type on console
php artisan vendor:publish --provider="Syscover\Navtools\NavtoolsServiceProvider"
3 - Register middlewares pulsar.navtools on file app/Http/Kernel.php add to routeMiddleware array
'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:
NAVTOOLS_URL_TYPE=lang
you can work with this urls
hrrp://mydomain.com/en/any-page
for urls type country
NAVTOOLS_URL_TYPE=country
you can work with this urls
hrrp://mydomain.com/us/any-page
for urls type lang-country
NAVTOOLS_URL_TYPE=lang-country
you can work with this urls
hrrp://mydomain.com/en-us/any-page
Set available languages in your web
NAVTOOLS_LANGS=en|es
Set available countries in your web
NAVTOOLS_COUNTRIES=us|gb|es
Set default country for your web
NAVTOOLS_DEFAULT_COUNTRY=es
On app\Http\routes.php file use this closure to implement routes with translation
Route::group(['middleware' => ['pulsar.navtools']], function() {
// write here your routes
});
You have several url configuration options depends on the chosen NAVTOOLS_URL_TYPE parameter:
Write your routes with lang variable
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
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
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.
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']);
});
Get country from user, a simple case
user_country(); // get country user
Get lang from user, a simple case
user_lang(); // get language user
To set routes you need to add lang or country parameters depending on NAVTOOLS_URL_TYPE.
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.
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().
You can change the language with change_lang helper
change_lang('en');
You can change the country with change_country helper
change_country('us');
Active route is a helper for to know when any route is active, has this properties:
A simple case
<a class="{{ active_route('home', 'active') }}" href="{{ route('home') }}">HOME</a>
case with multiples routes
<a class="{{ active_route(['home', 'home-en', 'home-es'], 'active') }}" href="{{ route('home') }}">HOME</a>
case with nested route
<a class="{{ active_route('product', 'active', true) }}" href="{{ route('product-01') }}">PRODUCT</a>
Get the route name of current route in other language
<a href="{{ route(get_lang_route_name('en')) }}">Change Lang</a>
Get the url of current route in other language
<a href="{{ get_lang_route('en') }}">Change Lang</a>
The Navtools is open-sourced software licensed under the MIT license.