@php $settings = \App\Models\HeaderSetting::first(); $socialLinks = \App\Models\SocialLinkSetting::first(); $menuCategories = \App\Models\Category::whereNull('parent_id') ->where('status', 'active') ->with([ 'direct_childs' => function ($q) { $q->where('status', 'active'); } ]) ->get(); $premiumMenuCategories = \App\Models\Category::where('is_premium', 1) ->with('direct_childs') ->orderBy('name') ->get(); use Illuminate\Support\Facades\Auth; $miniCart = null; $miniCartItems = collect(); $cartCount = 0; $cartTotal = 0; if (Auth::guard('customer')->check()) { // ✅ Logged user cart $miniCart = \App\Models\Cart::with('cart_details.product_options', 'cart_details.products') ->where('customer_id', Auth::guard('customer')->id()) ->first(); } else { // ✅ Guest cart using device_id $deviceId = session('device_id'); if ($deviceId) { $miniCart = \App\Models\UnAuthCart::with('cart_details.product_options', 'cart_details.products') ->where('device_id', $deviceId) ->first(); } } if ($miniCart) { $miniCartItems = $miniCart->cart_details; $cartCount = $miniCartItems->sum('quantity'); $cartTotal = $miniCart->total_price_after_discount ?? 0; } @endphp