DONE: auto add ic photo for existing customer

This commit is contained in:
ISMAIL MASSERAN
2026-09-09 10:27:48 +08:00
parent 120c32f781
commit f6110b6651
6 changed files with 91 additions and 8 deletions
@@ -289,6 +289,29 @@ class CustomersController extends Controller
return response(["no-data"], 200);
}
/**
* Store MyKad photo for an existing customer when gambar_mykad is still empty.
*/
public function storeMykadPhotoIfMissing(Request $request)
{
$icno = preg_replace('/[^0-9A-Za-z]/', '', (string) $request->input('icno'));
if ($icno === '') {
return response()->json(['error' => 'IC number is required.', 'stored' => false], 422);
}
if (!$request->filled('photo_base64')) {
return response()->json(['error' => 'Photo is required.', 'stored' => false], 422);
}
$response = Http::withOptions(['verify' => config('app.api_verify')])
->post(config('api.url') . '/api/customers/' . $icno . '/mykad-photo', [
'photo_base64' => $request->input('photo_base64'),
'photo_mime' => $request->input('photo_mime') ?: 'image/jpeg',
]);
return response()->json($response->json() ?? ['stored' => false], $response->status());
}
/**
* Show the form for creating a new resource.
*