has('limit')) { $perPage = $request->limit; } $contact = Auth::guard('customer')->id(); $narrowing = $request->only([ 'payment_number', 'payment_method_id', 'orderByField', 'orderBy', ]); $page = Payment::with(['customer', 'allocations.invoice', 'paymentMethod', 'creator']) ->whereCustomer($contact) ->applyFilters($narrowing) ->select('payments.*') ->orderByDesc('created_at') ->paginateData($perPage); // Counted afresh instead of taken off the page: the tally covers // everything on file for the contact, filters and paging aside. $recorded = Payment::whereCustomer($contact)->count(); return PaymentResource::collection($page)->additional([ 'meta' => ['paymentTotalCount' => $recorded], ]); } /** * Hand back a single receipt, looked up inside the portal's company and * narrowed to the signed-in contact. * * @param string $id * @return Response */ public function show(Company $company, $id) { $contact = Auth::guard('customer')->id(); $payment = $company->payments()->whereCustomer($contact)->where('id', $id)->first(); if ($payment === null) { return response()->json(['error' => 'payment_not_found'], Response::HTTP_NOT_FOUND); } return PaymentResource::make($payment->load(['allocations.invoice'])); } }