lupennat / import-export-card
Laravel Nova - Import Export Card
Requires
- php: ^7.4|^8.0
- laravel/nova: ^4.12
- maatwebsite/excel: ^3.1
- nova-kit/nova-packages-tool: ^1.3
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.16
README
Requirements
php: ^7.4 | ^8
laravel/nova: ^4
Installation
composer require lupennat/import-export-card
Usage
Next up, you must register the card(s). This is typically done in the card method of the corresponding resource or the NovaServiceProvider.
// in app/Nova/<Resource>.php public function cards(NovaRequest $request) { return [ new \Lupennat\ImportExportCard\ImportCard(self::class), (new \Lupennat\ImportExportCard\DownloadImportSampleCard(asset('import-samples/file.csv'))) ->withHelp('By importing you will insert a new row or update duplicate entries.'), new \Lupennat\ImportExportCard\ExportCard(self::class), ]; }
Customization
To customize the import/export process create a new importer/exporter class. The importer class is basically just an import implementation of the laravel-excel package. The exporter class is basically just an export implementation of the laravel-excel package.
The easiest way to get started is to extend Lupennat\ImportExportCard\BasicImporter
or Lupennat\ImportExportCard\BasicExporter
and overwrite the different methods. During the import process you may throw an exception of the type Lupennat\ImportExportCard\ImportException
with an error message visible for the user. You may also add a message(): String
method to customize the success message.
The custom importer/exporter classes can be registered on global or resource basis.
// app/Nova/User.php class User extends Resource { public static $importer = CustomImporter::class; public static $exporter = CustomExporter::class; // ... }
Credits
ImportExport Card is based on original Nova Import Card.