thomascombe/backpack-async-export
Composer 安装命令:
composer require thomascombe/backpack-async-export
包简介
This is a package to manage async export in Backpack for Laravel
README 文档
README
Laravel Backpack Async Export
This is a package to manage async export and import in Backpack for Laravel
Installation
You can install the package via composer:
composer require thomascombe/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 migrate
You 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', ];
Usage for export
Add export item in menu
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')\" />"
Create you export class
php artisan make:export UserExport --model=App/Models/User
For all details, have a look at Laravel Excel Package.
You can make your export class extends our LaravelExcel abstract.
Create your controller
php artisan backpack:crud {ModelName}
Your controller need to implement interface
use Thomascombe\BackpackAsyncExport\Http\Controllers\Admin\Interfaces\ExportableCrud; class {Name}CrudController extends CrudController implements ExportableCrud {}
Use awesome trait
use \Thomascombe\BackpackAsyncExport\Http\Controllers\Admin\Traits\HasExportButton;
Call method to add buttons
public function setup() { // ... $this->addExportButtons(); }
Add method to your CRUD controller
use Thomascombe\BackpackAsyncExport\Enums\ActionType; use Thomascombe\BackpackAsyncExport\Enums\ImportExportStatus; use Thomascombe\BackpackAsyncExport\Models\ImportExport; public function getExport(): 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, ]); } public function getExportParameters(): array { return []; }
Simple csv export
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.
use Illuminate\Database\Eloquent\Builder as EloquentBuilder; use Thomascombe\BackpackAsyncExport\Exports\SimpleCsv; class UserExport extends SimpleCsv { public function query(): EloquentBuilder { return User::query(); } public function headings(): array { return [ 'ID', 'Name', 'Email', ]; } /** * @param User $user * @return array */ public function map($user): array { return [ $user->id, $user->name, $user->email, ]; } }
Usage for import
Add import item in menu
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>"
Create you import class
php artisan make:import UserImport --model=App/Models/User
For all details, have a look at Laravel Excel Package
Create your controller
php artisan backpack:crud {Name}CrudController
Your controller need to implement interface
use Thomascombe\BackpackAsyncExport\Http\Controllers\Admin\Interfaces\ImportableCrud; class {Name}CrudController extends CrudController implements ImportableCrud {}
Use awesome trait
use Thomascombe\BackpackAsyncExport\Http\Controllers\Admin\Traits\HasImportButton;
Call method to add buttons
public function setup() { // ... $this->addImportButtons(); }
Add method to your CRUD controller
use Thomascombe\BackpackAsyncExport\Enums\ActionType; use Thomascombe\BackpackAsyncExport\Enums\ImportExportStatus; use Thomascombe\BackpackAsyncExport\Models\ImportExport; public function getImport(): 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, ]); } public function getImportParameters(): array { return [ 'private' => [ 'hint' => 'CSV file required', 'mimetypes' => ['text/csv', 'application/csv'], ], ]; }
Need more?
Override ImportExport model
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 { }
Update export name
Package allow to change export name with interface on your export
class: Thomascombe\BackpackAsyncExport\Exports\ExportWithName
namespace App\Exports; use Thomascombe\BackpackAsyncExport\Exports\ExportWithName; class UserExport implements ExportWithName { public static function getName(): string { return 'My export name'; } }
Multi export by CRUD?
You can easily have multi export on save CRUD.
Your CRUD controller need to
implement Thomascombe\BackpackAsyncExport\Http\Controllers\Admin\Interfaces\MultiExportableCrud interface.
public function getAvailableExports(): 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:
public function getExport*All*(): ImportExport { return ImportExport::create(...); } public function getExport*All*Parameters(): array { return [...]; }
Testing
composer test
Changelog
Please see CHANGELOG for more information on what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security Vulnerabilities
Please review our security policy on how to report security vulnerabilities.
Credits
License
The MIT License (MIT). Please see License File for more information.
thomascombe/backpack-async-export 适用场景与选型建议
thomascombe/backpack-async-export 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 30.52k 次下载、GitHub Stars 达 15, 最近一次更新时间为 2021 年 04 月 21 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「export」 「laravel」 「backpack」 「thomascombe」 「backpack-async-export」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 thomascombe/backpack-async-export 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 thomascombe/backpack-async-export 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 thomascombe/backpack-async-export 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Bulk export of sylius resources
Extended summernote fields for laravel backpack
Yii2 export extension
A simple API extension for SplFileObject
Export any WordPress post type to CVS.
Use a translation namespace vor mutliple translation files.
统计信息
- 总下载量: 30.52k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 15
- 点击次数: 20
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2021-04-21



