DeveloperBreeze

Context-Sensitive Data Development Tutorials, Guides & Insights

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

Laravel Best Practices for Sharing Data Between Views and Controllers

Tutorial November 16, 2024
php

   namespace App\Providers;

   use Illuminate\Support\ServiceProvider;
   use Illuminate\Support\Facades\View;

   class GlobalDataServiceProvider extends ServiceProvider
   {
       public function boot()
       {
           $globalConfig = [
               'app_mode' => 'live', // Example: Maintenance or live mode
               'support_email' => 'support@example.com',
           ];

           View::share('globalConfig', $globalConfig);
       }
   }
   <p>App Mode: {{ $globalConfig['app_mode'] }}</p>
   <p>Contact: {{ $globalConfig['support_email'] }}</p>