I get the last ID and increment it and store it as second ID of my invoice when two or three user request at the same time it store duplicated ID in DB. HERE IS THE CODE
$id_num = DB::table('slips')->latest('id')->first();
$now = \jDate::forge('now')->format('date');
$old = $id_num->date;
$slep_id = 0;
if($now>$old){
$slep_id = 1;
}
else{
$slep_id = $id_num->id_num+1;
}
$formatted_slep = sprintf("%04d",$slep_id);
Now when I store it in the DB it some times it duplicate
$slip = new Slip;
$slip->id = $formatted_slep;
$slip->save();
from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2sBi8av
via IFTTT
Aucun commentaire:
Enregistrer un commentaire