Laravel 5.3 在代码中将 001 递增到 002
Laravel 5.3 Increment 001 to 002 in code
我有一个 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";
}
}
谢谢
我有一个 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";
}
}
谢谢