DeveloperBreeze

Efficient Data Loading. Development Tutorials, Guides & Insights

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

Leveraging Service Providers to Manage Global Data in Laravel

Tutorial November 16, 2024
php

   namespace App\Http\Controllers;

   use Illuminate\Support\Facades\View;

   class ExampleController extends Controller
   {
       public function index()
       {
           $globalPreferences = View::shared('globalPreferences');

           return view('example', [
               'apiLimit' => $globalPreferences['api_limit'],
               'appMode' => $globalPreferences['app_mode'],
           ]);
       }
   }

If the data needs to change during the application lifecycle (e.g., a feature toggle), you can update it dynamically.