require(); $customer = $request->user()->customerProfiles()->where('businessId', $business->id)->firstOrFail(); $summary = $loyalty->summary($business, $customer); $history = $customer->loyaltyAccounts()->with(['transactions' => fn ($query) => $query->latest('createdAt')->limit(20), 'programme'])->get()->flatMap->transactions->sortByDesc('createdAt')->take(20); return view('customer.loyalty', compact('business', 'customer', 'summary', 'history')); } }