如果在Excel中输入日期不使用格式,ex输入字符串,我得到了错误
floor(): Argument #1 ($num) must be of type int|float, string given`
如果使用日期格式,它工作正常,但当输入不使用格式日期,我得到的错误。
如何处理这一点?
这是我的代码
public function collection(Collection $rows)
{
foreach ($rows as $key => $row) {
$izin = Izin::where('nama_izin', $row['id_izins'])->where('id_users', Auth::id())->pluck('id')->first();
$customMessages = [
$izin => 'Perhatikan ' . '"' . $row['id_izins'] . '"' . ' Pada baris ' . $key + 2 . ' tidak terdaftar',
];
Validator::make($rows->toArray(), [
$izin => 'required',
], $customMessages)->validate();
LaporIzin::create([
'nama_perusahaan' => $row['nama_perusahaan'],
'alamat_perusahaan' => $row['alamat_perusahaan'],
'tanggal_masuk' => Date::excelToDateTimeObject($row['tanggal_masuk']),
'tanggal_izin' => Date::excelToDateTimeObject($row['tanggal_izin']),
'nomor_izin' => $row['nomor_izin'],
'id_izins' => $izin,
'id_users' => Auth::id(),
]);
}
}
public function rules(): array
{
return [
'nama_perusahaan' => 'required',
'nomor_izin' => 'required',
];
}
如何处理使用条件或解决方法?
1条答案
按热度按时间bq9c1y661#
当日期输入为空时,您可以检查空日期,也许这会有所帮助,