Coder Social home page Coder Social logo

qirolab / laravel-excel-export-import-example Goto Github PK

View Code? Open in Web Editor NEW
23.0 1.0 23.0 324 KB

Laravel Excel export, import tutorial with example

Home Page: https://qirolab.com

PHP 79.10% HTML 20.90%
laravel laravel-package laravel-excel excel-export phpspreadsheet excel-import

laravel-excel-export-import-example's Introduction

Laravel Excel Export & Import example

It's pretty easy to export to Excel and import from Excel, with great Laravel Excel package. This package supercharge your Laravel collections and export them directly to an Excel or CSV document.

In the tutorial videos, you will learn:

  • How to format exported columns
  • How to add header or additional columns
  • How to handle date formats, formulas etc.
  • How to process large files
  • How to catch exceptions and validate import data

1. Laravel Excel Export Tutorial

Laravel Excel Export data in Excel

2. Laravel Excel Import Tutorial

Laravel Excel Import to Database

laravel-excel-export-import-example's People

Contributors

hkp22 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

laravel-excel-export-import-example's Issues

Fails to skip data with errors

On failure doesn't skip errors but goes on to add it to the database.

Environment

maatwebsite/excel verrsion:3.1
PHP Version: 8.0

Below is the model

public function rules(): array
  {
      return [
    'cus_name' => 'bail|required|string|max:255',
    'cau_cat' => 'required|integer|between:1,4',
    'cus_cat' => 'required|integer|between:1,4',
    'cus_type' => 'required|integer|between:1,2',
    'cus_idnum' =>  'required|string|max:255',
    'cus_idtype' => 'required|integer|between:1,16',
    'cus_type' => 'required|integer|between:1,4',
    'listtype_id' =>'required|integer|between:1,4',
    'cus_dob' => 'required|date|date_format:Y-m-d',
      ];
  }
  public function chunkSize(): int
  {
      return 1000;
  }

  public static function afterImport(AfterImport $event)
  {
  }

  public function onFailure(Failure ...$failure)
  {
      Log::stack(['import-failure-logs'])->info(json_encode($failure));
  }

The code in the controller

 $file = $request->file('file')->store('import');

        $import = new CustomersImport;
       
      
          $import->import($file);
          foreach ($import->failures() as $failure) {
            $failure->row(); // row that went wrong
            $failure->attribute(); // either heading key (if using heading row concern) or column index
            $failure->errors(); // Actual error messages from Laravel validator
            $failure->values(); // The values of the row that has failed.
       }

        if ($import->failures()->isNotEmpty()) {
            return back()->withFailures($import->failures());
        }

Catch an error while importing huge CSV in queue using laravel excel

I am using ShouldQueue method to have the large CSV into Queue but the errors of validations I am not able to catch them!

public function registerEvents(): array { return [ ImportFailed::class => function(ImportFailed $event) { dd($event); // This I will write into the FILE or send EMAIL but the job runs successfully but validation errors keep empty. $this->importedBy->notify(new ImportHasFailedNotification); }, ]; }

My code looks like below...

public function registerEvents(): array { return [ ImportFailed::class => function(ImportFailed $event) { $filename = public_path('tmp').'/validation_error.txt'; $myfile = fopen($filename, "w"); fwrite($myfile, "domo"); fclose($myfile); }, ]; }

I am in hope that if there is any error validation_error.txt file will have "Demo" inside it.

I just wanted to add those errors in a file and email to the user that's it.

Also, I have crossed verify by removing ShouldQueue it gives me proper errors for email already exists a kind of.

Please help if you have any ideas! Thanks!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.