PHP code example of hoyvoy / laravel-subdomain-localization

1. Go to this page and download the library: Download hoyvoy/laravel-subdomain-localization library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

hoyvoy / laravel-subdomain-localization example snippets


	...
    'Localize'  => Hoyvoy\Localization\Facades\Localize::class,
    'Router'    => Hoyvoy\Localization\Facades\Router::class,
	...

	...
    'localize' => \Hoyvoy\Localization\Middleware\Localization::class,
	...

	...
	use Hoyvoy\Localization\Facades\Localize;
	...
    public function boot(Router $router)
    {
        // This will guess a locale from the current HTTP request
        // and set the application locale
        Localize::detectLocale();
        
        parent::boot($router);
    }
	...

    // Without the localize middleware, this route can be reached with or without language subdomain
    Route::get('logout', 'AuthController@logout');
    
    // With the localize middleware, this route cannot be reached without language subdomain
    Route::group([ 'middleware' => [ 'localize' ]], function() {
    
        Route::get('welcome', 'WelcomeController@index');
    
    });

    return [
    
        // route name => route translation
        'welcome' => 'welcome',
        'user_profile' => 'user/{username}',
    
    ];

    return [
    
        // route name => route translation
        'welcome' => 'bienvenue',
        'user_profile' => 'utilisateur/{username}',
    
    ];

    Route::group([ 'middleware' => [ 'localize' ]], function() {
    
        Route::get(Router::resolve('routes.welcome'), 'WelcomeController@index');
    
    });

    <a href="{{ Router::current('fr') }}">See the french version</a>

    @foreach (Router::getCurrentVersions() as $locale => $url)
    <a href="{{ $url }}">{{ $locale }}</a>
    @endforeach

    <a href="{{ Router::url('user_profile', [ 'username' => 'JohnDoe' ], 'fr') }}">See JohnDoe's profile</a>

php artisan vendor:publish --provider="Hoyvoy\Localization\LocalizationServiceProvider" --tag="config"