Skip to content

Normalising Rows for Validation when using OnEachRow #2985

Answered by MrThePlague
MrThePlague asked this question in Q&A
Discussion options

You must be logged in to vote

For anyone that might be trying to accomplish this same thing in the future, I was able to use prepareForValidation() to normalise the row prior to applying validation rules. This also works correctly with SkipsOnFailure and SkipsFailures.

Example Import

class ExampleImport implements OnEachRow, WithHeadingRow, WithChunkReading, SkipsOnFailure, WithValidation
{
    use SkipsFailures, Importable;

    private $example;

    public function __construct(string $exampleId)
    {
        $this->exampleId = $exampleId;
    }

    public function prepareForValidation($data, $index)
    {
        /**
        * Normalise the column names into a standard
        * e.g. name could be either 'name' o…

Replies: 2 comments 1 reply

Comment options

You must be logged in to vote
1 reply
@MrThePlague
Comment options

Comment options

You must be logged in to vote
0 replies
Answer selected by MrThePlague
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants