corealg/excel-validator

This package helps you to validate your excel sheet cell by cell. You do not need to store data blindly, you can rule each cell to match your expectation.

v1.0.1 2021-12-20 11:02 UTC

This package is auto-updated.

Last update: 2024-10-20 18:05:10 UTC


README

Build Status License

This package helps you to validate your excel sheet cell by cell. You do not need to store data blindly, you can rule each cell to match your expectation.

Installation

Require this package with composer.

composer require corealg/excel-validator

Usage

<?php
// initilaize Core Excel Validator
$excelValidator = new ExcelValidator();

// make rules
$rules = [
    'first_name' => 'required',
    'last_name' => 'nullable',
    'email' => 'required|email|max:30',
    'joining_date' => 'date:Y-m-d'
];

// validate the sheet
$response = $excelValidator->validate($_FILES['file'], $rules);

// Success response
// [
//   "status" => "success"
//   "code" => 200
//   "errors" => []
//   "data" => [
//     1 => [
//       "first_name" => "Mizanur"
//       "last_name" => "Rahman"
//       "email" => "test@example.com"
//       "joining_date" => "2021-01-01"
//     ]
//   ]
// ]

// Validation error Response
// [
//   "status" => "error"
//   "code" => 422
//   "errors" => [
//      0 => "The First name is required at row 11"
//      1 => "The Joining date is not valid date format at row 18"
//      2 => "The Name is required at row 20"
//   ]
//   "data" => null
// ]

Creating Rules

Use column's name for your rule's index (all lower case and replace the black space with the underscore [_])

e.g. for column name First Name your rule will be

<?php 
$rule = [
    'first_name' => 'required'
];

Check this link to get the available validation rules: https://github.com/rakit/validation#available-rules

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Authors

License

MIT License

Copyright (c) 2021 CoreAlg