第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

發(fā)現(xiàn)意外數(shù)據(jù)。發(fā)現(xiàn)意外數(shù)據(jù)。追蹤數(shù)據(jù)

發(fā)現(xiàn)意外數(shù)據(jù)。發(fā)現(xiàn)意外數(shù)據(jù)。追蹤數(shù)據(jù)

PHP
狐的傳說 2023-08-06 15:31:36
我創(chuàng)建了 Excel 導(dǎo)入函數(shù),它工作正常,直到我注意到日期沒有正確插入,所以我嘗試格式化日期,就像Y-m-d在 MySql 中正確存儲(chǔ)一樣,但 Carbon 給出了以下錯(cuò)誤Carbon\Exceptions\InvalidFormatException發(fā)現(xiàn)意外數(shù)據(jù)。發(fā)現(xiàn)意外數(shù)據(jù)。追蹤數(shù)據(jù)在Excel中我可能有d/m/Y或者Y/m/d所以我想在數(shù)據(jù)庫中格式化為tored我的導(dǎo)入代碼public function model(array $row){    return new Staff([        'employee_no'               => $row['id'],        'name'                      => $row['name'],        'address'                   => $row['address'],        'fathers_name'              => $row['father'],        'dob'                       => $this->transformDate($row['dob']),        'blood_group'               => $row['blood_group'],        'phone'                     => $row['phone'],        'password'                  => Hash::make($row['id']),    ]);}public function transformDate($value, $format = 'Y-m-d'){    try {        return \Carbon\Carbon::instance(\PhpOffice\PhpSpreadsheet\Shared\Date::excelToDateTimeObject($value));    } catch (\ErrorException $e) {        return \Carbon\Carbon::createFromFormat($format, $value);    }}我的員工模型class Staff extends Authenticatable{  protected $fillable = [    'name', 'employee_no', 'designation_id', 'fathers_name', 'dob', 'identification_mark', 'blood_group', 'phone', 'address', 'height', 'rfid_no', 'building_id', 'password',  ];  protected $casts = ['dob'];}正確的方法是什么,還是我必須采用新的format方法dob
查看完整描述

1 回答

?
楊__羊羊

TA貢獻(xiàn)1943條經(jīng)驗(yàn) 獲得超7個(gè)贊

Carbon::createFromFormat($format, $time)應(yīng)該接收給定的格式$time,而不是您想要轉(zhuǎn)換成的格式。嘗試將其更改為$format = 'd/m/Y',正如您所說,這是您期望從記錄中獲得的格式。

之后,您只需在 Carbon 對(duì)象上創(chuàng)建->toDateString()或即可獲取數(shù)據(jù)庫格式。->toDateTimeString()

查看完整回答
反對(duì) 回復(fù) 2023-08-06
  • 1 回答
  • 0 關(guān)注
  • 120 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)