Laravel-excel: [QUESTION] How to address validation rules like 'gte'

Created on 20 Feb 2020  路  2Comments  路  Source: Maatwebsite/Laravel-Excel

Prerequisites

Versions

  • PHP version: 7.1.30
  • Laravel version: 5.8.37
  • Package version: 3.1.18

Description

I just ran into an issue where I was using a 'gte' (greater than or equal to) validator with the WithValidation concern, and the import was always throwing a validation error no matter what the values I was using in the relevant fields. I finally figured out that I needed to include an asterisk before the field name, since it is validating in batches. I.e.:

public function rules(): array
{
    return [
        // This doesn't work:
        'maximum_percent' => 'gte:minimum_percent',
        // This does:
        'maximum_percent' => 'gte:*.minimum_percent',
    ];
}

I'm submitting this as a question, because I'm not sure if it's preferable to address this as a note in the documentation (certainly the easier way), or if it would be better to make it so that it works without the asterisk, if that's possible?

Additional Information

In case it makes a difference, I'm using the WithValidation concern along with WithBatchInserts and WithChunkReading.

question

All 2 comments

Would prefer a note in the docs for now. I think it's probably tricky to solve this for all possible validation rules.

Thanks for the response @patrickbrouwers! I've submitted a suggested note as a PR to the docs, so I'll go ahead and close this question.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

MakamuEvans picture MakamuEvans  路  21Comments

shineraj94 picture shineraj94  路  25Comments

hardikdangar picture hardikdangar  路  38Comments

mnabialek picture mnabialek  路  26Comments

adnandogar picture adnandogar  路  32Comments