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

Using the Singleton Pattern to Optimize Shared Data in Laravel

Alternatively, inject the singleton into the controller’s constructor:

   namespace App\Http\Controllers;

   class HomeController extends Controller
   {
       protected $sharedData;

       public function __construct()
       {
           $this->sharedData = app('sharedData');
       }

       public function index()
       {
           return view('home', [
               'maxUploads' => $this->sharedData->maxUploads,
               'apiRateLimit' => $this->sharedData->apiRateLimit,
               'theme' => $this->sharedData->theme,
           ]);
       }
   }

Nov 16, 2024
Read More