<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
redsquirrelstudio / laravel-backpack-import-operation example snippets
'providers' => ServiceProvider::defaultProviders()->merge([
/*
* Package Service Providers...
*/
//Some other package's service providers...
RedSquirrelStudio\LaravelBackpackImportOperation\Providers\ImportOperationProvider::class,
])->toArray(),
class ExampleCrudController extends CrudController
{
use \Backpack\CRUD\app\Http\Controllers\Operations\ListOperation;
use \Backpack\CRUD\app\Http\Controllers\Operations\CreateOperation;
use \Backpack\CRUD\app\Http\Controllers\Operations\UpdateOperation;
use \Backpack\CRUD\app\Http\Controllers\Operations\DeleteOperation;
use \Backpack\CRUD\app\Http\Controllers\Operations\ShowOperation;
use \RedSquirrelStudio\LaravelBackpackImportOperation\ImportOperation;
//...
//Probably some more CRUD config...
protected function setupImportOperation()
{
CRUD::addColumn([
'name' => 'id',
'label' => 'ID',
'type' => 'number',
]);
CRUD::addColumn([
'name' => 'name',
'label' => 'Name',
'type' => 'text',
]);
}
//Fetch functions or something...
protected function setupImportOperation()
{
$this->withoutPrimaryKey();
//Some column config...
protected function setupImportOperation()
{
CRUD::setValidation(CustomerRequest::class);
//Some column config...
protected function setupImportOperation()
{
$this->setExampleFileUrl('https://example.com/link-to-your-download/file.csv');
//Some column config...
namespace App\Imports\Columns;
use RedSquirrelStudio\LaravelBackpackImportOperation\Columns\ImportColumn;
class ExampleColumn extends ImportColumn
{
public function output(): mixed
{
return $this->data;
}
}
//...
// Aliases for import column types to be used in operation setup
'column_aliases' => [
'array' => Columns\ArrayColumn::class,
'boolean' => Columns\BooleanColumn::class,
'date' => Columns\DateColumn::class,
'number' => Columns\NumberColumn::class,
'text' => Columns\TextColumn::class,
'column_type' => App\Imports\Columns\ExampleColumn::class
]
use RedSquirrelStudio\LaravelBackpackImportOperation\Interfaces\WithCrudSupport;
class CustomImport implements OnEachRow, WithCrudSupport
{
public function __construct(int $import_log_id, ?string $validator = null)
{
}
public function onRow(Row $row)
{
$row = $row->toArray();
//Your import handling
protected function setupImportOperation()
{
$this->setImportHandler(CustomImport::class);
//Some column config...
//...
protected function setupImportOperation()
{
$this->disableUserMapping();
//...
//...
protected function setupImportOperation()
{
$this->deleteFileAfterImport();
//...
//...
protected function setupImportOperation()
{
$this->queueImport();
//...
//...
//Filesystem disk to store uploaded import files
'disk' => "s3",
//Path to store uploaded import files
'path' => "/2023/application-name/imports",
//...
//...
//Queue to dispatch import jobs to
'queue' => 'import-queue',
//Chunk size for reading import files
'chunk_size' => 300,
//...
[
//The Import being processed
'import_log' => RedSquirrelStudio\LaravelBackpackImportOperation\Models\ImportLog::class,
//The data from the spreadsheet row
'row_data' => array(),
//The created/update model from the row
'entry' => \Illuminate\Database\Eloquent\Model::class
]
[
//The Import being processed
'import_log' => RedSquirrelStudio\LaravelBackpackImportOperation\Models\ImportLog::class,
//The data from the spreadsheet row
'row_data' => array(),
]
public function setup()
{
//...
CRUD::denyAccess('import');
//...
}
config/app.php
config/backpack/operations/import.php
bash
php artisan migrate
$this->data
$this->getConfig()
$this->getModel()
config/backpack/operations/import.php
config/backpack/operations/import.php
config/backpack/operations/import.php
config/backpack/operations/import.php
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.