PHP code example of topview-digital / laravel-lang-switcher

1. Go to this page and download the library: Download topview-digital/laravel-lang-switcher 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/ */

    

topview-digital / laravel-lang-switcher example snippets


php artisan lang-switch:publish



return [

    /*
    |--------------------------------------------------------------------------
    | Laravel-Language-Switcher Database Settings
    |--------------------------------------------------------------------------
    |
    | Here are database settings for Laravel-Language-Switcher builtin tables connction.
    |
    */

    'database' => [
        // Database connection for guards tables.
        'connection' => '',

    ],

    //the field name of the storage in  cookie
    'field' => 'locale',
];


php artisan lang-switch:install

    protected $middlewareGroups = [
        'web' => [
            // ...
            \TopviewDigital\LangSwitcher\Middleware\LangSwitcher::class,
        ],
        //...

//Auth::user() is the guard method to get login user model, which could access the user field for setting locale
\TopviewDigital\LangSwitcher\Model\LangSwitcher::registerGuard(['class'=>'Auth','method'=>'user','middleware'=>'web']);