- How do I install haruncpi/laravel-id-generator in a Laravel app?
- Install it with composer require haruncpi/laravel-id-generator. On modern Laravel versions you may need to loosen the Composer constraint, and you should reserve --ignore-platform-reqs for throwaway environments only. Then verify the facade resolves and any publishable config loads correctly. There is no schema ownership or migration to run, so install effort is measured in minutes.
- Does laravel-id-generator support Laravel 10 or Laravel 11?
- Not officially. The last release was 2019-10-28, so its Composer constraints almost certainly target Laravel 5.x and 6.x, and it has not been validated against Laravel 9, 10 or 11. You can fork it or relax the constraint, but you must retest against current framework string-ID conventions and your PHP version. On greenfield Laravel 10/11 projects, treat HasUuids, HasUlids or a database sequence as the default instead.
- How do I generate a prefixed invoice or order ID in Laravel?
- You pass the target table and column along with your prefix, length and suffix options, and the generator returns the next formatted value by reading the current max in that column. That makes invoice numbers, order references and ticket codes straightforward. Only adopt it where a human-readable sequential identifier is a genuine product requirement; for purely internal IDs a UUID or ULID is simpler and avoids the extra dependency.
- Is laravel-id-generator safe under concurrent requests?
- No. It is a read-max-then-insert generator, which is not atomic, so two concurrent requests can compute the same ID. Without a unique index on the column this corrupts data silently; with one it surfaces as a duplicate-key error, and retry logic is your responsibility rather than the package's. Wrap generation and insert in the same transaction, add a unique constraint, and add bounded retry on conflict.
- How do I reset the ID sequence daily, monthly or yearly?
- The package supports sequence resets, which is what you use for per-day, per-month or per-year counters in formatted IDs. Confirm the reset behaviour against your real data, because soft-deleted rows, gaps after rollback and prefix collisions across tenants all affect what the max-value lookup returns. Test resets explicitly on the same database engine you run in production, not just on sqlite in CI.
- What happens when the generated ID exceeds the fixed length?
- Zero-padding overflows once the sequence grows past the configured length, so the ID no longer matches your expected format and may break downstream parsing. Add a test for that boundary and decide in advance whether to widen the length, add a rollover rule, or fail loudly. Gaps also appear after rolled-back transactions, which matters if continuity is an audit or compliance requirement rather than cosmetic.
- Is laravel-id-generator a good alternative to UUIDs or ULIDs?
- Only when you specifically need a human-readable, sequential, prefixed identifier like an invoice number or ticket code. For internal primary keys, Laravel's native UUID and ULID support is strictly better: no extra dependency, no per-insert table lookup and no race condition. The package has little differentiation versus roughly twenty lines of your own code in a dedicated sequences table.
- How does it handle soft deletes, gaps and alphanumeric sequences?
- Because the next value comes from the max value in the target column, soft-deleted rows and gaps change what the generator sees, and string ordering can behave differently from numeric ordering. Prefix collisions across tenants and alphanumeric formats need explicit testing on your production engine. Note that sqlite and MySQL or Postgres do not order strings the same way, so CI results alone are not sufficient.
- Does it work with MySQL and PostgreSQL, and how does it perform at scale?
- There is no verifiable database-agnostic sequence handling, so validate on both your CI engine and production engine. Table and column names are typically interpolated into the query, which is safe when hardcoded but dangerous when derived from user input, so never pass request data into them. Performance is fine at thousands of rows, but the per-insert max lookup becomes a write hot spot once the table reaches millions of rows under load.
- Is haruncpi/laravel-id-generator still maintained and should I fork it?
- Maintenance is the main risk: no release since 2019-10-28, no visible security policy, a low bus factor and around 277 stars, so do not plan on upstream fixes. Preferred path is replacing it with a sequences table updated via SELECT ... FOR UPDATE inside the insert transaction, or a native Postgres sequence or MySQL auto-increment formatted at the presentation layer. If call sites already depend on the API, vendor the single class into app/Support behind an internal IdGenerator contract and add the unique index, bounded retry and tests for padding, prefix and overflow yourself.