Laravel-excel: How can i ignore a row,cell and column empty or validate it in Laravel-Excel 3

Created on 2 Nov 2018  路  12Comments  路  Source: Maatwebsite/Laravel-Excel

Prerequisites

Versions

  • PHP version: 7.2
  • Laravel version: 5.7
  • Package version: 3.1

Description

Additional Information

Any additional information, configuration or data that might be necessary to reproduce the issue.

Most helpful comment

You can just use any Laravel validation rule that exists. https://laravel.com/docs/5.7/validation#available-validation-rules

return [
    'email' => 'required',
];

All 12 comments

Thanks for submitting the ticket. Unfortunately the information you provided is incomplete. We need to know which version you use and how to reproduce it. Please include code examples. Before we can pick it up, please check (https://github.com/Maatwebsite/Laravel-Excel/blob/3.0/.github/ISSUE_TEMPLATE.md) and add the missing information. To make processing of this ticket a lot easier, please make sure to check (https://laravel-excel.maatwebsite.nl/docs/3.0/getting-started/contributing) and double-check if you have filled in the issue template correctly. This will allow us to pick up your ticket more efficiently. Issues that follow the guidelines correctly will get priority over other issues.

@TheThai212 please show us your code what you have right now. Have you checked the documentation for row validation: https://laravel-excel.maatwebsite.nl/3.1/imports/validation.html ?
For skipping rows we have an example in our docs too: https://laravel-excel.maatwebsite.nl/3.1/imports/model.html#importing-to-models

i readed it but what is '[email protected]' in your rules, Can i check it require?
`public function rules(): array
{
return [
'email' => Rule::in(['[email protected]']),

         // Above is alias for as it always validates in batches
         '*.email' => Rule::in(['[email protected]']),
    ];
}`

You can just use any Laravel validation rule that exists. https://laravel.com/docs/5.7/validation#available-validation-rules

return [
    'email' => 'required',
];

thanks, it work but dont alert messages
this's my code:
`
public function rules(): array
{
return [
'ke_point' => 'required',
'tra_point' => 'required',
'pha_point' => 'required',
];
}

    public function customValidationMessages()
{
    return [
        'ke_point' => 'Please enter ke point',
        'tra_point' => 'Please enter tra point',
        'pha_point' => 'Please enter pha point',
    ];
}`

Am i wrong?

it work but dont alert messages I don't understand what you mean with that.

@TheThai212 Try adding .required. With messages you have to indicate the specific rule.

public function customValidationMessages()
{
    return [
        'ke_point.required' => 'Please enter ke point',
    ];
}`

More info in Laravel docs: https://laravel.com/docs/5.7/validation#custom-error-messages

oki. many thanks

how get all failures at the end, using collection and not models??

@patrickbrouwers
I don't want to validate if all cell is empty in a row.How to skip this empty row.
e.g-i have 4 column and 3 row.i only want to validate A column and B column in a row.
All cell of a second row is empty, i don't want to validate this second row but A column is empty in third row.so i want to check this third row and save error message in databases.Please,
how can i do that.

This is a way to avoid empty rows

        /** @var CellCollection $row */
        foreach ($data as $row) {
            if (!$row->filter()->isEmpty()) {
                // do somthing 
            }
        }

Hello,

I wrote answer about this here:
https://stackoverflow.com/a/60858640/2395363

Hope it helps!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

matthewslouismarie picture matthewslouismarie  路  3Comments

contifico picture contifico  路  3Comments

muhghazaliakbar picture muhghazaliakbar  路  3Comments

wwendorf picture wwendorf  路  3Comments

alejandri picture alejandri  路  3Comments