complete Complete User Request Submission section RAD-1

This commit is contained in:
2026-01-03 19:14:30 +03:30
commit 7137ec5792
393 changed files with 152602 additions and 0 deletions
@@ -0,0 +1,19 @@
<?php
namespace App\Services\Document;
use App\Models\Document;
use RuntimeException;
class DocumentCodeService
{
public function generate(int $tries = 10): string
{
for ($i = 0; $i < $tries; $i++) {
$code = str_pad((string) random_int(0, 999999), 6, '0', STR_PAD_LEFT);
if (! Document::where('code', $code)->exists()) {
return $code;
}
}
throw new RuntimeException('Unable to generate unique code');
}
}