This is a package to manage async export and import in Backpack for Laravel
You can install the package via composer:
composer require webqamdev/backpack-async-export| Version | PHP | Laravel | Backpack |
|---|---|---|---|
| 1.x | 7.4 - ^8.0 | ^8.0 - ^9.0 - ^10.0 | 4.1.* - ~5.0 |
| 2.x | ^8.1 | ^9.0 - ^10.0 | ~5.5 - ~6.0 |
| 3.x | ^8.1 | ^10.0 | ~6.0 |
| 4.x | ^8.2 | ^11.0 | ~6.0 |
| 5.x | ^8.2 | ^12.0 - ^13.0 | ^7.0 |
You can publish and run the migrations with:
php artisan vendor:publish --provider="Thomascombe\BackpackAsyncExport\BackpackAsyncExportServiceProvider" --tag="backpack-async-export-migrations"
php artisan migrateYou can publish the config file with:
php artisan vendor:publish --provider="Thomascombe\BackpackAsyncExport\BackpackAsyncExportServiceProvider" --tag="backpack-async-export-config"This is the contents of the published config file:
return [
'feature_enabled' => [
'export' => true,
'import' => true,
],
'user_model' => 'App\Models\User',
'import_export_model' => Thomascombe\BackpackAsyncExport\Models\ImportExport::class,
'admin_export_route' => 'export',
'admin_import_route' => 'import',
'export_memory_limit' => '2048M',
'disk' => 'local',
];php artisan backpack:add-sidebar-content "<li class='nav-item'><a class='nav-link' href='{{ backpack_url('export') }}'><i class='nav-icon la la-file-export'></i> <span>Export</span></a></li>"# or
php artisan backpack:add-menu-content "<x-backpack::menu-item title='Export' icon='la la-file-export' :link=\"backpack_url('export')\" />"php artisan make:export UserExport --model=App/Models/UserFor all details, have a look at Laravel Excel Package.
You can make your export class extends our LaravelExcel abstract.
php artisan backpack:crud {ModelName}useThomascombe\BackpackAsyncExport\Http\Controllers\Admin\Interfaces\ExportableCrud;
class {Name}CrudController extends CrudController implements ExportableCrud {}use \Thomascombe\BackpackAsyncExport\Http\Controllers\Admin\Traits\HasExportButton;publicfunctionsetup()
{
// ...$this->addExportButtons();
}useThomascombe\BackpackAsyncExport\Enums\ActionType;
useThomascombe\BackpackAsyncExport\Enums\ImportExportStatus;
useThomascombe\BackpackAsyncExport\Models\ImportExport;
publicfunctiongetExport(): ImportExport
{
return ImportExport::create([
ImportExport::COLUMN_USER_ID => backpack_user()->id,
ImportExport::COLUMN_ACTION_TYPE => ActionType::Export,
ImportExport::COLUMN_STATUS => ImportExportStatus::Created,
ImportExport::COLUMN_FILENAME => sprintf('export/users_%s.xlsx', now()->toIso8601String()),
ImportExport::COLUMN_EXPORT_TYPE => UserExport::class,
]);
}
publicfunctiongetExportParameters(): array
{
return [];
}It may sometimes be necessary to export large amounts of data. PhpSpreadsheet (used behind the hood by this package) does not always offer the best performance. In this case, it is recommended to use the low-level functions of PHP, such as fputcsv.
This package has an abstract class SimpleCsv which can be extended to use this export mode. Of course, it is more limited and only allows you to define a query, headers and a mapping between the model and the data table to be exported.
useIlluminate\Database\Eloquent\BuilderasEloquentBuilder;
useThomascombe\BackpackAsyncExport\Exports\SimpleCsv;
class UserExport extends SimpleCsv
{
publicfunctionquery(): EloquentBuilder
{
return User::query();
}
publicfunctionheadings(): array
{
return [
'ID',
'Name',
'Email',
];
}
/** * @param User $user * @return array */publicfunctionmap($user): array
{
return [
$user->id,
$user->name,
$user->email,
];
}
}php artisan backpack:add-sidebar-content "<li class='nav-item'><a class='nav-link' href='{{ backpack_url('import') }}'><i class='nav-icon la la-file-import'></i> <span>Import</span></a></li>"php artisan make:import UserImport --model=App/Models/UserFor all details, have a look at Laravel Excel Package
php artisan backpack:crud {Name}CrudControlleruseThomascombe\BackpackAsyncExport\Http\Controllers\Admin\Interfaces\ImportableCrud;
class {Name}CrudController extends CrudController implements ImportableCrud {}useThomascombe\BackpackAsyncExport\Http\Controllers\Admin\Traits\HasImportButton;publicfunctionsetup()
{
// ...$this->addImportButtons();
}useThomascombe\BackpackAsyncExport\Enums\ActionType;
useThomascombe\BackpackAsyncExport\Enums\ImportExportStatus;
useThomascombe\BackpackAsyncExport\Models\ImportExport;
publicfunctiongetImport(): ImportExport
{
return ImportExport::create([
ImportExport::COLUMN_USER_ID => backpack_user()->id,
ImportExport::COLUMN_ACTION_TYPE => ActionType::Import->value,
ImportExport::COLUMN_STATUS => ImportExportStatus::Created,
ImportExport::COLUMN_FILENAME => '',
ImportExport::COLUMN_EXPORT_TYPE => UserImport::class,
]);
}
publicfunctiongetImportParameters(): array
{
return [
'private' => [
'hint' => 'CSV file required',
'mimetypes' => ['text/csv', 'application/csv'],
],
];
}You can override ImportExport model using config : import_export_model.
Your model class need to implement \Thomascombe\BackpackAsyncExport\Models\ImportExport.
class ImportExport extends \Thomascombe\BackpackAsyncExport\Models\ImportExport
{
}Package allow to change export name with interface on your export
class: Thomascombe\BackpackAsyncExport\Exports\ExportWithName
namespaceApp\Exports;
useThomascombe\BackpackAsyncExport\Exports\ExportWithName;
class UserExport implements ExportWithName
{
publicstaticfunctiongetName(): string
{
return'My export name';
}
}You can easily have multi export on save CRUD.
Your CRUD controller need to
implement Thomascombe\BackpackAsyncExport\Http\Controllers\Admin\Interfaces\MultiExportableCrud interface.
publicfunctiongetAvailableExports(): array
{
return [
'default' => null,
'all' => 'All',
];
}Array keys: key for query params and dynamic method name
Array values: Export name (display in CRUD button)
For each new export you have to add news methods:
publicfunction getExport*All*(): ImportExport
{
return ImportExport::create(...);
}
publicfunction getExport*All*Parameters(): array
{
return [...];
}composer testPlease see CHANGELOG for more information on what has changed recently.
Please see CONTRIBUTING for details.
Please review our security policy on how to report security vulnerabilities.
The MIT License (MIT). Please see License File for more information.



