try {
$import = new ImportMark($data);
Excel::import($import, $request->file('xls')->store('files'));
return redirect()->route('marks.index')->with('success', __('marks.batch_success', ['count'=>'']));
} catch (\Maatwebsite\Excel\Validators\ValidationException $e) {
$failures = $e->failures();
foreach ($failures as $failure) {
$failure->row(); // row that went wrong
$failure->attribute(); // either heading key (if using heading row concern) or column index
$failure->errors(); // Actual error messages from Laravel validator
$failure->values(); // The values of the row that has failed.
}
return redirect()->back()->withInput()->with('xls_errors', $failures);
} catch(\Exception $ex){
return redirect()->back()->withInput()->with('failure', $ex->getMessage());
}
На данный момент мне удалось добиться следующего.

Однако мне не удалось получить имя листа, проверка которого не удалась. Мой лист выглядит так.

Я пытаюсь показать имя листа (1031-Comp. Mathematics), в котором проверка не удалась. Вот мой класс ImportMark
class ImportMark implements WithMultipleSheets, WithEvents{
protected $data;
protected $no_of_sheets;
protected $totalRows;
public $sheetNames;
public $sheetData;
public function __construct($data){
$this->data = $data;
$this->sheetData = array_fill(0, 4, new ImportSubjectWiseSheet($this->data));
}
public function sheets(): array{
return $this->sheetData;
}
public function registerEvents(): array
{
return [
BeforeImport::class => function (BeforeImport $event) {
$this->totalRows = $event->getReader()->getTotalRows();
},
BeforeSheet::class => function(BeforeSheet $event) {
$this->sheetNames[] = $event->getSheet()->getTitle();
}
];
}
public function getSheetNames() {
return $this->sheetNames;
}
}
Подробнее здесь: https://stackoverflow.com/questions/770 ... validators