DeveloperBreeze

Laravel Views Development Tutorials, Guides & Insights

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

Laravel Best Practices for Sharing Data Between Views and Controllers

Tutorial November 16, 2024
php

For frequently accessed but infrequently changing data, use caching.

   use Illuminate\Support\Facades\Cache;

   public function boot()
   {
       $navigationMenu = Cache::rememberForever('navigation_menu', function () {
           return [
               ['title' => 'Home', 'url' => '/'],
               ['title' => 'About', 'url' => '/about'],
           ];
       });

       View::share('navigationMenu', $navigationMenu);
   }