I need to import attendance reports to my system using Laravel Excel Library, But I have some problem with the wrong data validation. For example, I have the following excel data that I want to import into my database.
As you can see John has put his finger three times into the machine, But I want to Insert only the first and last record into my database using Laravel excel library. And also the struct of my database is like the following picture.
As you can see In my DB structure I have time_in and time_out in the same row, but in the excel file time _in is in one row, and time_out is in another row, So how I can insert this excel file correctly in my Database.
You need to parse the data before sending it to the Database (DB), not just directly feed it to your DB. A simple explode
with ' '
as the separator can split the Date/Time
column then use DateTime
to format the date and time, meanwhile keep tracking which of the data you need as Time In
and Time Out
Assuming: $date = explode(' ',$dateTime);
$date[0] = the date, 2/1/2021
$date[1] = the time, 7:31
Assuming the date is j/n/Y
, attendance_date
can be filled as $attDate = date_format(DateTime::createFromFormat('j/n/Y', trim($date[0]),'Ym-d');
may be you have to parse data before store it into database or your can change the Excel file contents
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.