Home > Net >  Stop Laravel Excel Import if a Column has duplicate Values in Excel File
Stop Laravel Excel Import if a Column has duplicate Values in Excel File

Time:04-07

I am using Laravel Excel and what I want is that whenever I upload the excel file and the file has a duplicate row based on some column so how to stop importing data and give the error to the user to check the file first and then upload the file.

Note: I am using Collection method with batchSize and chunkSize with the header row and I am not inserting a new row I just update some records based on column condition when matches update some fields. I am using Laravel 7.

Thank You

I tried this rule but this is not case for me.

    public function rules(): array
    {
        return [
            'email' => Rule::unique('employees', 'email')
        ];
    }

CodePudding user response:

You're looking for the distinct validation rule:

https://laravel.com/docs/8.x/validation#rule-distinct

public function rules(): array
{
    return [
        'email' => 'distinct',
    ];
}
  • Related