@php
// Get the last application number
$lastNumber = \App\Models\Application::orderByDesc('id')->value('number');
if ($lastNumber) {
// Extract numeric part after APP-
preg_match('/APP-(\d+)/', $lastNumber, $matches);
$lastNumeric = isset($matches[1]) ? (int) $matches[1] : 0;
$newNumeric = $lastNumeric + 1;
} else {
$newNumeric = 1;
}
// Add random 3-digit number to make it harder to guess
$randomPart = mt_rand(100, 999);
// Pad numeric part to 10 digits + append random
$serial_number = 'APP-' . str_pad($newNumeric, 10, '0', STR_PAD_LEFT) . $randomPart;
@endphp
{{ __('global.required') }}