Close Menu
    DevStackTipsDevStackTips
    • Home
    • News & Updates
      1. Tech & Work
      2. View All

      Sunshine And March Vibes (2025 Wallpapers Edition)

      May 31, 2025

      The Case For Minimal WordPress Setups: A Contrarian View On Theme Frameworks

      May 31, 2025

      How To Fix Largest Contentful Paint Issues With Subpart Analysis

      May 31, 2025

      How To Prevent WordPress SQL Injection Attacks

      May 31, 2025

      Windows 11 version 25H2: Everything you need to know about Microsoft’s next OS release

      May 31, 2025

      Elden Ring Nightreign already has a duos Seamless Co-op mod from the creator of the beloved original, and it’ll be “expanded on in the future”

      May 31, 2025

      I love Elden Ring Nightreign’s weirdest boss — he bargains with you, heals you, and throws tantrums if you ruin his meditation

      May 31, 2025

      How to install SteamOS on ROG Ally and Legion Go Windows gaming handhelds

      May 31, 2025
    • Development
      1. Algorithms & Data Structures
      2. Artificial Intelligence
      3. Back-End Development
      4. Databases
      5. Front-End Development
      6. Libraries & Frameworks
      7. Machine Learning
      8. Security
      9. Software Engineering
      10. Tools & IDEs
      11. Web Design
      12. Web Development
      13. Web Security
      14. Programming Languages
        • PHP
        • JavaScript
      Featured

      Oracle Fusion new Product Management Landing Page and AI (25B)

      May 31, 2025
      Recent

      Oracle Fusion new Product Management Landing Page and AI (25B)

      May 31, 2025

      Filament Is Now Running Natively on Mobile

      May 31, 2025

      How Remix is shaking things up

      May 30, 2025
    • Operating Systems
      1. Windows
      2. Linux
      3. macOS
      Featured

      Windows 11 version 25H2: Everything you need to know about Microsoft’s next OS release

      May 31, 2025
      Recent

      Windows 11 version 25H2: Everything you need to know about Microsoft’s next OS release

      May 31, 2025

      Elden Ring Nightreign already has a duos Seamless Co-op mod from the creator of the beloved original, and it’ll be “expanded on in the future”

      May 31, 2025

      I love Elden Ring Nightreign’s weirdest boss — he bargains with you, heals you, and throws tantrums if you ruin his meditation

      May 31, 2025
    • Learning Resources
      • Books
      • Cheatsheets
      • Tutorials & Guides
    Home»Development»Early View Data Preparation with Laravel View Creators

    Early View Data Preparation with Laravel View Creators

    January 3, 2025

    Early View Data Preparation with Laravel View Creators

    Laravel’s View Creators allow you to prepare data immediately after view instantiation, earlier than View Composers, making them perfect for setting up essential view data or optimizing performance.

    use IlluminateSupportFacadesView;
    // Registering a View Creator
    View::creator('dashboard', DashboardCreator::class);
    

    Let’s explore a practical example of managing a dynamic application menu:

    <?php
    
    namespace AppViewCreators;
    
    use AppServicesMenuService;
    use IlluminateViewView;
    use IlluminateSupportFacadesAuth;
    
    class ApplicationMenuCreator
    {
        protected $menuService;
    
        public function __construct(MenuService $menuService)
        {
            $this->menuService = $menuService;
        }
    
        public function create(View $view)
        {
            $user = Auth::user();
            
            $view->with([
                'mainMenu' => $this->menuService->getMainMenu($user),
                'quickActions' => $this->menuService->getQuickActions($user),
                'recentItems' => $this->menuService->getRecentItems($user),
                'notifications' => $this->menuService->getPendingNotifications($user)
            ]);
        }
    }
    
    // In your AppServiceProvider
    public function boot()
    {
        View::creator('layouts.app', ApplicationMenuCreator::class);
    }
    
    // Usage in layouts/app.blade.php
    <div class="sidebar">
        <nav>
            @foreach($mainMenu as $menuItem)
                <a href="{{ $menuItem['url'] }}" class="{{ $menuItem['active'] ? 'active' : '' }}">
                    {{ $menuItem['label'] }}
                </a>
            @endforeach
        </nav>
        
        @if(count($quickActions))
            <div class="quick-actions">
                @foreach($quickActions as $action)
                    <button onclick="handleAction('{{ $action['id'] }}')">
                        {{ $action['label'] }}
                    </button>
                @endforeach
            </div>
        @endif
    </div>
    

    View Creators provide early data preparation for your views, ensuring critical data is available as soon as the view is instantiated.

    Hostinger

    The post Early View Data Preparation with Laravel View Creators appeared first on Laravel News.

    Join the Laravel Newsletter to get all the latest
    Laravel articles like this directly in your inbox.

    Source: Read More 

    Facebook Twitter Reddit Email Copy Link
    Previous ArticleUsing AI to Manage Translations in Laravel
    Next Article Microsoft confirms Microsoft Rewards accounts suspended by mistake

    Related Posts

    Artificial Intelligence

    Markus Buehler receives 2025 Washington Award

    May 31, 2025
    Artificial Intelligence

    LWiAI Podcast #201 – GPT 4.5, Sonnet 3.7, Grok 3, Phi 4

    May 31, 2025
    Leave A Reply Cancel Reply

    Continue Reading

    iOS 18.1 update worsen your iPhone battery health? Don’t let this spec fool you

    Development

    CVE-2025-47229 – GNU PSPP Denial of Service Vulnerability

    Common Vulnerabilities and Exposures (CVEs)

    AI chatbot startup WotNot leaks 346,000 files, including passports and medical records

    Development

    Error’d: Beer and Peanuts

    Development

    Highlights

    News & Updates

    The best Minecraft game is free on Amazon Prime

    April 5, 2025

    Pick it up quick before it’s too late! Source: Read More / Windows Central

    GitLab Security Update – Patch for XSS, DoS & Account Takeover Vulnerabilities

    April 24, 2025

    Rilasciato Celluloid 0.28: un lettore video open source basato su mpv

    April 5, 2025

    Data Structures and Algorithms (DSA): A Complete Tutorial

    January 15, 2025
    © DevStackTips 2025. All rights reserved.
    • Contact
    • Privacy Policy

    Type above and press Enter to search. Press Esc to cancel.