<?php

namespace App\Providers;

use Illuminate\Support\ServiceProvider;
use Illuminate\Support\Facades\View;
use App\Models\Category;

class ViewServiceProvider extends ServiceProvider
{
    public function boot(): void
    {
        // Share $allCategories with EVERY view that uses the header partial.
        // This replaces passing it manually from every controller method.
        View::composer('*', function ($view) {
            if (!$view->offsetExists('allCategories')) {
                $view->with('allCategories', Category::orderBy('category_name')->get());
            }
        });
    }
}