DeveloperBreeze

Language Preferences Development Tutorials, Guides & Insights

Unlock 1+ expert-curated language preferences tutorials, real-world code snippets, and modern dev strategies. From fundamentals to advanced topics, boost your language preferences skills on DeveloperBreeze.

Tutorial
php

Using Laravel Config and Localization Based on Site Settings

   namespace App\Providers;

   use Illuminate\Support\ServiceProvider;
   use Illuminate\Support\Facades\Schema;
   use Illuminate\Support\Facades\Config;
   use Illuminate\Support\Facades\App;
   use App\Models\SiteSetting;

   class AppServiceProvider extends ServiceProvider
   {
       public function boot()
       {
           if (Schema::hasTable('site_settings')) {
               $settings = SiteSetting::pluck('value', 'key');

               // Set application name
               Config::set('app.name', $settings['app_name'] ?? Config::get('app.name'));

               // Set application timezone
               Config::set('app.timezone', $settings['app_timezone'] ?? Config::get('app.timezone'));

               // Set application language
               App::setLocale($settings['app_language'] ?? Config::get('app.locale'));
           }
       }
   }
  • Config::set: Dynamically updates Laravel’s configuration values.
  • App::setLocale: Sets the application’s locale for localization features.

Nov 16, 2024
Read More