我的格式为registration_id
KUTWJH210117001
。下次用户发布registration_id
时我想将其增加到KUTWJH210117002
,
但我得到的输出为:
KUTWJH210117001 // the first time
KUTWJH2101172 // next time it will be
KUTWJH2101173 // and so on
守则
public function setRegistrationIdAttribute($rid)
{
$getLastRegistrationId = Driver::orderBy('id', 'desc')->first()->registration_id;
$getDateToCheck = substr($getLastRegistrationId , 6, 6);
if($getDateToCheck === date('dmy')) {
$toIncrement = substr($getLastRegistrationId, -1);
$increment = float($toIncrement++); //i'm incrementing here
$this->attributes['registration_id'] = $rid.date('dmy').$increment;
}
else
{
$this->attributes['registration_id'] = $rid.date('dmy')."001";
}
}
谢谢