0

I have install stancl/tenancy to create multi store tenant . and i have mcamara to setup store default language from settings database table .

App\Http\Middleware\Tenantenvironment

   if (Schema::hasTable('languages') && Schema::hasTable('settings')):
           $default_language       = settingHelper('default_language');
        if (!empty($default_language)) :
            Config::set('app.locale', $default_language);
        endif;
        //supported language setting to laravellocalization
        $languageList              =  Language::where('status',1)->get();
        $supportedLocales          = array();
  
        if ($languageList->count() > 0) :
            foreach ($languageList as $lang) :
                $langConfigs            = $lang->languageConfig->select('name', 'script', 'native', 'regional')->get();
                foreach ($langConfigs as $langConfig) :
                    $langConfig->flag_icon = $lang->flag;
                    $supportedLocales[$lang->locale] = $langConfig;
                endforeach;
            endforeach;
          //  LaravelLocalization::setSupportedLocales($supportedLocales);
            Config::set('laravellocalization.supportedLocales', $supportedLocales);

        endif;
       endif;

App\Http\Kernel

        'InitializeTenancyByPath'=>  \Stancl\Tenancy\Middleware\InitializeTenancyByPath::class,
        'InitializeTenancyByDomain'=> \Stancl\Tenancy\Middleware\InitializeTenancyByDomain::class,
        'tenantenvironment' => \App\Http\Middleware\Tenantenvironment::class,
        'PreventAccessFromCentralDomains'=> \Stancl\Tenancy\Middleware\PreventAccessFromCentralDomains::class,
        'subdomain' => SubdomainMiddleware::class,
        'customdomain' => CustomdomainMiddleware::class,
        'Isinstalled' => \App\Http\Middleware\IsinstalledMiddleware::class,
        'localize'                => \Mcamara\LaravelLocalization\Middleware\LaravelLocalizationRoutes::class,
        'localizationRedirect'    => \Mcamara\LaravelLocalization\Middleware\LaravelLocalizationRedirectFilter::class,
        'localeSessionRedirect'   => \Mcamara\LaravelLocalization\Middleware\LocaleSessionRedirect::class,
        'localeCookieRedirect'    => \Mcamara\LaravelLocalization\Middleware\LocaleCookieRedirect::class,
        'localeViewPath'          => \Mcamara\LaravelLocalization\Middleware\LaravelLocalizationViewPath::class,

routes\tenant.php

Route::group(['middleware' => ['InitializeTenancyByDomain','PreventAccessFromCentralDomains','web','tenantenvironment']], function () {
  
    require_once __DIR__.'/admin.php';
   
    
});

routes\admin.php

Route::middleware(['XSS'])->group(function () {
    Route::group(
        [
            'prefix' => LaravelLocalization::setLocale(),
            'middleware' => ['localeSessionRedirect', 'localizationRedirect', 'localeViewPath']
        ], function () {`
                Route::get('dashboard', [DashboardController::class, 'index'])->name('dashboard');
    });
});

but my problem is : The default language does not change, it always remains English because the language settings are configured before tenant I have try https://stackoverflow.com/a/67903302/14262982 to initialize defualt language but not working

Is there any way to connect tenent database and get languages on service provider?

Mo Nabil
  • 11
  • 5

0 Answers0