DeveloperBreeze

Laravel Programming Tutorials, Guides & Best Practices

Explore 51+ expertly crafted laravel tutorials, components, and code examples. Stay productive and build faster with proven implementation strategies and design patterns from DeveloperBreeze.

Tutorial
php

Leveraging Service Providers to Manage Global Data in Laravel

Use a singleton pattern or event listener to refresh the data dynamically. For example, reset shared data when global settings are updated:

   public function boot()
   {
       Event::listen('settings.updated', function () {
           $globalPreferences = [
               'api_limit' => Setting::get('api_limit'),
               'app_mode' => Setting::get('app_mode'),
               'feedback_form_enabled' => Setting::get('feedback_form_enabled'),
           ];

           view()->share('globalPreferences', $globalPreferences);
       });
   }

Nov 16, 2024
Read More
Tutorial
php

How to Dynamically Manage Application Settings in Laravel

Open the generated file in database/seeders and populate the settings table:

   namespace Database\Seeders;

   use Illuminate\Database\Seeder;
   use Illuminate\Support\Facades\DB;

   class SettingsSeeder extends Seeder
   {
       public function run()
       {
           DB::table('settings')->insert([
               ['key' => 'timezone', 'value' => 'UTC'],
               ['key' => 'notifications_enabled', 'value' => 'true'],
               ['key' => 'api_rate_limit', 'value' => '100'],
           ]);
       }
   }

Nov 16, 2024
Read More