I have the following code to read a xlsx spreadsheet but this seems to have some issue:
Excel::load($filePath, function ($reader) use ($classId) {
// Getting all results
$reader->get();
// Loop through all sheets
$reader->each(function ($sheet) use ($classId) {
// Loop through all rows
$sheet->each(function ($row) use ($classId) {
if (filter_var($row, FILTER_VALIDATE_EMAIL)) {
$invitation = new Invitations();
$invitation->email = $row;
$invitation->status = 0;
$invitation->class_id = $classId;
$invitation->token = str_random(10);
$invitation->sent = 0;
$invitation->created_at = time();
$invitation->save();
}
});
});
});
The problem with this code is not all the fields are being checked for ex: I have email address on field A5 and than I have another email address on D7 and so on... it only takes D7 value not A5... if I put all in one column let say B1,B2,B3 and so on it works fine. How can I make it work wherever there is an email address on any field and insert it into db.