Add function to fetch a single customer

This commit is contained in:
2025-10-29 14:21:55 +01:00
parent 2b56d6fe82
commit b943c17a0f
@@ -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
*/