Enhancing Error Handling in Laravel-Excel Integration with FilementPHP

Hi,

We are attempting to import data from an excel file using FilementPHP via https://laravel-excel.com and display multiple error messages in the interface. However, the Laravel fail closure only provides the option to pass a single error for validation when self-defined.

Is it feasible to show multiple errors that can subsequently be displayed?

class SomeRule implements ValidationRule
{
    public function validate(string $attribute, mixed $value, \Closure $fail): void
    {
        try {
            Importer::fromArray(Excel::toArray(new Validate(), $value));
        } catch (ValidationException $exception) {
            $fail(implode(',', collect($exception->errors())->first()));
        } catch (NoTypeDetectedException|InvalidArgumentException $exception) {
            $fail($exception->getMessage()) <-- only allow one error;
        }
    }
}
Laravel Excel
Laravel Excel is intended at being Laravel-flavoured PhpSpreadsheet: a simple, but elegant wrapper with the goal of simplifying exports and imports.
Was this page helpful?