Level 58
You can use the validate method of the Import class provided by the SpartnerNL/Laravel-Excel package. This method takes a closure as an argument, which allows you to validate the file before it is imported.
For example, if you want to check if the file contains a header element called name, you can do the following:
use SpartnerNL\Laravel\Excel\Imports\Import;
$import = new Import();
$import->validate(function($file) {
if (!$file->has('name')) {
throw new \Exception('The file does not contain the required header element "name"');
}
});
If the file does not contain the required header element, an exception will be thrown and the import will be aborted.