Download the PHP package alfonsobries/laravel-spreadsheet-importer without Composer
On this page you can find all versions of the php package alfonsobries/laravel-spreadsheet-importer. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download alfonsobries/laravel-spreadsheet-importer
More information about alfonsobries/laravel-spreadsheet-importer
Files in alfonsobries/laravel-spreadsheet-importer
Package laravel-spreadsheet-importer
Short Description Sheetjs Laravel Spreadsheet Importer
License MIT
Homepage https://github.com/alfonsobries/laravel-spreadsheet-importer
Informations about the package laravel-spreadsheet-importer
Laravel Faster Spreadsheet Importer
This package works together with the xlsx-laravel-spreadsheet-importer CLI tool to quickly import spreadsheets from xlsx files an other compatible formats and then store the values into temporal database tables that are way easier to work with.
Because we use Node instead of PHP we can import larger xlsx files in just a few seconds, and because we will work with a SQL table the operations with the data are considerably faster.
- Includes a command that expect the data according to the cli tool and trigger an observable event with the progress of the import.
- Adds a Trait that add the ability to your model to work with the temporal data as easy as any Eloquent relationship.
- Once the import is finished triggers another observable event so you can know when you can continue with the following operations related with your import.
- Manages multiple files format, see (https://www.npmjs.com/package/xlsx#file-formats)
- Compatible with PostgreSQL as MySQL
Installation
You can install the package via composer:
You also will need the npm package (check alfonsobries/xlsx-laravel-spreadsheet-importer for more info)
Optionally publish the config files by running:
Configure your model
The files that you will import usually will be associated to one Model, also your Model will be used to store the progress of the import.
Start by adding the InteractsWithImporter
trait and the Importable
contract to the Model.
You will also need to define the methods in the Importable
contract
Add the neccesary columns to the Importable
Model
Your Model will need a few columns to store the progress and status of the import, to add those columns you can create a migration like the following (just change the table name for your model table name):
Once the Model is configured and you import a spreadsheet you can interact with the data stored in the temporal table using the tempData()
relationship.
For example lets say that your spreadsheet has a sales column and you want the total:
Import a file
For importing a file you will need to call the xlsx-laravel-spreadsheet-importer
command using the instructions here but to make your work easy this package includes a StartImport
Job that will build the command for you (dont forget to add the neccesary columns to store the progres to your model).
You can dispatch the job at any moment, it receive the importable
Model as a param.
For example, you can call the job once you save your model in a store
method in a controller (assuming that your model is associating a file and will return a valid file_path in the getFileToImportPath()
method):
That job will create and trigger the Node command, then the Node command will call the ReportImporterProgress
artisan command every time has some progress to inform, finally the artisan command will trigger a ImporterProgressEvent
that you can listen with your custom event listener or by adding ImporterProgressEventListener
that comes in this package, that listener is responsible to store the progress of your import into your Model:
To configure the event listener add the following lines into your app/Providers/EventServiceProvider.php
:
Testing
For running the tests you will need to install the dependencies and have a valid testing database
- Install the composer packages
composer install
- Because this package interacts with a database you will need to define a
.env
with a valid mysql or postgresql database data (useenv.example
as an example) - Also you need to install the npm dependency
npm install
Changelog
Please see CHANGELOG for more information what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security
If you discover any security related issues, please email [email protected] instead of using the issue tracker.
Credits
- Alfonso Bribiesca
- All Contributors
License
The MIT License (MIT). Please see License File for more information.