From 6855fb35218fc0eb0df476eb32b4147d9374d253 Mon Sep 17 00:00:00 2001 From: Daniel Stock Date: Wed, 29 Oct 2025 14:21:55 +0100 Subject: [PATCH] Add function to fetch a single customer --- app/Http/Controllers/CustomerController.php | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/app/Http/Controllers/CustomerController.php b/app/Http/Controllers/CustomerController.php index 62b5e94..76526d3 100644 --- a/app/Http/Controllers/CustomerController.php +++ b/app/Http/Controllers/CustomerController.php @@ -4,6 +4,7 @@ use App\Models\Customer; use App\Support\ApiDataTransformer; +use Pest\ArchPresets\Custom; class CustomerController extends Controller { @@ -21,6 +22,20 @@ public function index() }); } + public function single($id) + { + $customer = Customer::with(['contacts' => function ($query) { + $query->orderBy('is_primary', 'desc'); + }, 'paymentTerms'])->findOrFail($id); + + $customerArray = $customer->toArray(); + if ($customer->paymentTerms) { + $customerArray['payment_terms'] = $customer->paymentTerms->toArray(); + unset($customerArray['payment_terms_id']); + } + return ApiDataTransformer::snakeToCamel($customerArray); + } + /** * Generate a random available customer number */