PHP code example of thomascombe / backpack-async-export
1. Go to this page and download the library: Download thomascombe/backpack-async-export library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
thomascombe / backpack-async-export example snippets
use Thomascombe\BackpackAsyncExport\Http\Controllers\Admin\Interfaces\ExportableCrud;
class {Name}CrudController extends CrudController implements ExportableCrud {}
use \Thomascombe\BackpackAsyncExport\Http\Controllers\Admin\Traits\HasExportButton;
public function setup()
{
// ...
$this->addExportButtons();
}
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 [];
}
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,
];
}
}
use Thomascombe\BackpackAsyncExport\Http\Controllers\Admin\Interfaces\ImportableCrud;
class {Name}CrudController extends CrudController implements ImportableCrud {}
use Thomascombe\BackpackAsyncExport\Http\Controllers\Admin\Traits\HasImportButton;
public function setup()
{
// ...
$this->addImportButtons();
}
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
class ImportExport extends \Thomascombe\BackpackAsyncExport\Models\ImportExport
{
}
namespace App\Exports;
use Thomascombe\BackpackAsyncExport\Exports\ExportWithName;
class UserExport implements ExportWithName
{
public static function getName(): string
{
return 'My export name';
}
}
public function getAvailableExports(): array
{
return [
'default' => null,
'all' => 'All',
];
}
public function getExport*All*(): ImportExport
{
return ImportExport::create(...);
}
public function getExport*All*Parameters(): array
{
return [...];
}