public function validate(LaravelExcelReader $reader) { if (!$this->rules()) { return; } $count = 0; $reader->each(function (CellCollection $row) use(&$count) { if ($count > 0 || !$this->hasHeader()) { $mapped = []; try { $mapped = $this->map($row->all()); } catch (Exception $e) { $this->log->log('Validator mapping failed'); throw $e; } $validator = Validator::make($mapped, $this->rules(), []); if ($validator->fails()) { throw new Exception('Invalid row #' . $count . ': ' . implode(', ', $validator->messages()->all())); } } $count++; }); }
/** * Select sheets by index * @param array $sheets * @return $this */ public function selectSheetsByIndex($sheets = array()) { $sheets = is_array($sheets) ? $sheets : func_get_args(); $this->reader->setSelectedSheetIndices($sheets); return $this; }
/** * Sets up the Maatwebsite\Excel reader by skipping header rows. * * @param \Maatwebsite\Excel\Readers\LaravelExcelReader */ protected function setUpReader(LaravelExcelReader &$reader) { // skips the header and example rows $reader->skip(self::$HEADER_ROWS - 1); // Excel lib skips 1 by default }