You have to manually manage it, either by using a model event on your Laravel app, or use a INSTEAD OF trigger on your database.
Some references:
- https://laravel.com/docs/9.x/eloquent#events
- https://docs.microsoft.com/en-us/sql/relational-databases/triggers/dml-triggers?view=sql-server-ver15
- https://docs.microsoft.com/en-us/sql/t-sql/statements/create-trigger-transact-sql?view=sql-server-ver15
What you basically need is to run something like this:
SELECT COALESCE(MAX([AUTOINCREMENT]), 0) + 1 AS NewId
FROM [table]
WHERE [OtherID] = ?
Before inserting a new record and using this new id.
If you do it on the Laravel/PHP side, be sure to use a transaction and use the ->lockForUpdate() when selecting the values, to avoid two concurrent requests ending up with the same id.
More reading:
- https://laravel.com/docs/9.x/database#database-transactions
- https://laravel.com/docs/9.x/queries#pessimistic-locking
All Laravel links should work if you replace 9.x by 8.x in case you are using Laravel version 8