I did a basic CRUD using Eloquent.
My problem is when it's time to create. I use the code below:
public function store(Request $request)
{
$subscription = new Subscription;
// Basic Data
$subscription->custom_id = '10001';
$subscription->service_id = 1;
$subscription->imported = 1;
$subscription->review = 0;
$subscription->inserted_by = \Auth::user()->id;
$subscription->save();
}
Pretty simple. I can enter data normally. However, when an error occurs (for example the error Duplicate entry ) and I'm going to insert the next record, it skips a number (id) in the database. See pictures below
1) I enter a record
2)Ireproducedanerror
3)Ienterthenextrecordnormally(10002)
Notice that the next record is with id
3, and I believe it should be 2, because it did not enter the 2nd record because I forced an error.
Why does this happen?
Can it be avoided?
Does this happen with all systems or only with Eloquent?