PHPackages                             konafets/laravel-csv-validator - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Validation &amp; Sanitization](/categories/validation)
4. /
5. konafets/laravel-csv-validator

ActiveLibrary[Validation &amp; Sanitization](/categories/validation)

konafets/laravel-csv-validator
==============================

A Laravel package to validate CSV files using cyberduck/laravel-excel

92833[1 issues](https://github.com/Konafets/laravel-csv-validator/issues)PHP

Since Dec 4Pushed 8y ago3 watchersCompare

[ Source](https://github.com/Konafets/laravel-csv-validator)[ Packagist](https://packagist.org/packages/konafets/laravel-csv-validator)[ RSS](/packages/konafets-laravel-csv-validator/feed)WikiDiscussions develop Synced today

READMEChangelogDependenciesVersions (1)Used By (0)

Laravel Csv and Excel Validator
===============================

[](#laravel-csv-and-excel-validator)

[![Latest Stable Version](https://camo.githubusercontent.com/c13bf148d829e70f7c531581a1e7c7247129e654e0ec90b6f01b3750023ed033/68747470733a2f2f706f7365722e707567782e6f72672f6b6f6e61666574732f6c61726176656c2d6373762d76616c696461746f722f762f737461626c65)](https://packagist.org/packages/konafets/laravel-csv-validator) [![Total Downloads](https://camo.githubusercontent.com/519353db5ae16c041e30d70e7ec8e4577af05e184da754c3f31c8274641c55e9/68747470733a2f2f706f7365722e707567782e6f72672f6b6f6e61666574732f6c61726176656c2d6373762d76616c696461746f722f646f776e6c6f616473)](https://packagist.org/packages/konafets/laravel-csv-validator) [![Latest Unstable Version](https://camo.githubusercontent.com/44715f6bae2ca33f15914364536929478dba82590081e2bfdf72411b40cf7ad8/68747470733a2f2f706f7365722e707567782e6f72672f6b6f6e61666574732f6c61726176656c2d6373762d76616c696461746f722f762f756e737461626c65)](https://packagist.org/packages/konafets/laravel-csv-validator) [![License](https://camo.githubusercontent.com/705bdad6e3a6ef13d48808e3f7a9cd8633551a59647a3a28c06fd29a792e6b50/68747470733a2f2f706f7365722e707567782e6f72672f6b6f6e61666574732f6c61726176656c2d6373762d76616c696461746f722f6c6963656e7365)](https://packagist.org/packages/konafets/laravel-csv-validator) [![Monthly Downloads](https://camo.githubusercontent.com/2cc61c0ac587e13b1575620f659ec9c1c5c9982b02adbb5d4a0f8e335ecf5fb3/68747470733a2f2f706f7365722e707567782e6f72672f6b6f6e61666574732f6c61726176656c2d6373762d76616c696461746f722f642f6d6f6e74686c79)](https://packagist.org/packages/konafets/laravel-csv-validator)

A Laravel 5.5 package to validate csv, excel and OpenOffice data.

The idea behind the package is simple: Just use the same validation logic and syntax as in request validating.

**The package does so far only supports CSV / Excel files with a header row**

Installation
============

[](#installation)

Execute composer command.

```
composer require konafets/laravel-csv-validator:1.0-dev

```

Thanks to Laravels Auto-Discovery, you are done. The ServiceProvider and Alias is registered automatically.

Basic usage
===========

[](#basic-usage)

```
$csvPath = 'employees.csv';
$rules = [
    'First Name' => 'required|string',
    'Last Name' => 'required|string',
    'Year of Birth' => 'required|numeric',
];

$csvValidator = CsvValidator::make($csvPath, $rules);

if($csvValidator->fails()) {
    $errors = $csvValidator->getErrors();
} else {
    $csvData = $csvValidator->getData();
}

```

Rules
=====

[](#rules)

```
$rules = [
    'First Name' => 'required|string',
    'Last Name' => 'required|string',
    'Year of Birth' => 'required|numeric',
];

```

In this example, the first row of the CSV need to have three columns named `First Name`, `Last Name` and `Year of Birth`. There might be others columns as well in your file but we don't care for them.
This keys will be used as attribute names for error message.

For more details of the rules [see](https://laravel.com/docs/5.5/validation#available-validation-rules).

Error messages
==============

[](#error-messages)

You can get error messages after calling fails().

```
$errors = $csvValidator->getErrors();

foreach ($errors as $rowIndex => $row) {
    foreach ($row as $column => $messages) {
        echo 'Row ' . $rowIndex . ', Col ' . $column . ': ' . implode(',' , $messages) . '';
    }
}

```

CSV data
========

[](#csv-data)

You also can get CSV data after calling fails().

```
$csvData = $csvValidator->getData();

```

Exception
=========

[](#exception)

The Validator throws an exception when:

- your CSV does not have any data.
- Heading key not found.

Some example code

```
try {
    $csvValidator = CsvValidator::make($csv_path, $rules, $encoding);

    if($csvValidator->fails()) {
        // Do something..
    }
} catch (\Exception $e) {
    echo $e->getMessage();
}

```

Credits
=======

[](#credits)

This package is heavily inspired by . They use `maatwebsite/excel` as the underlying Excel library, while this package uses `box/sprout`.

###  Health Score

24

—

LowBetter than 32% of packages

Maintenance18

Infrequent updates — may be unmaintained

Popularity19

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity41

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

### Community

Maintainers

![](https://www.gravatar.com/avatar/b6aaf47df633cf9e260061e733e6cb82af4dabde0023bbcd2096dac330f41eb9?d=identicon)[Konafets](/maintainers/Konafets)

---

Top Contributors

[![Konafets](https://avatars.githubusercontent.com/u/363363?v=4)](https://github.com/Konafets "Konafets (14 commits)")

---

Tags

csvexcellaravelopenofficephpspout

### Embed Badge

![Health badge](/badges/konafets-laravel-csv-validator/health.svg)

```
[![Health](https://phpackages.com/badges/konafets-laravel-csv-validator/health.svg)](https://phpackages.com/packages/konafets-laravel-csv-validator)
```

###  Alternatives

[webmozart/assert

Assertions to validate method input/output with nice error messages.

7.6k894.0M1.2k](/packages/webmozart-assert)[bensampo/laravel-enum

Simple, extensible and powerful enumeration implementation for Laravel.

2.0k15.9M104](/packages/bensampo-laravel-enum)[swaggest/json-schema

High definition PHP structures with JSON-schema based validation

48612.5M73](/packages/swaggest-json-schema)[stevebauman/purify

An HTML Purifier / Sanitizer for Laravel

5325.6M19](/packages/stevebauman-purify)[ashallendesign/laravel-config-validator

A package for validating your Laravel app's config.

217905.3k5](/packages/ashallendesign-laravel-config-validator)[crazybooot/base64-validation

Laravel validators for base64 encoded files

1341.9M8](/packages/crazybooot-base64-validation)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
