aliportfolio/csv-importer

The package allows you to upload a CSV file and import the data into database.

v1.0.0 2023-06-03 04:04 UTC

This package is not auto-updated.

Last update: 2024-05-05 06:38:02 UTC


README

The package allows you to upload a CSV file and import the data into database.

Features

  • CSV Importer
  • TXT Importer
  • Fields Validator

Installation

Install with command

  composer require aliportfolio/csv-importer

Usage/Examples

First, create custom importer (ex: CategoryImport.php)

<?php

namespace App\Imports;

use Aliportfolio\CsvImporter\CsvImporter;

class CategoryImport extends CsvImporter
{
    // Model Name
    protected $table = 'Category';

    protected $mapping = [
        'name' => 'name'
    ];

    // Validation Data
    protected $rules = [
        'name' => 'required|string'
    ];
}

In controller call the CategoryImport Class

$import = new CategoryImport();
$import->import($request->file('csv_file'));