PHP code example of dandysi / laravel-batch-upload
1. Go to this page and download the library: Download dandysi/laravel-batch-upload 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/ */
class CreateCategoriesProcessor implements ProcessorInterface
{
public function config(): ProcessorConfig
{
return ProcessorConfig::create()
->column('code', 'Code', ' 'name' => $row['name]
]);
//more than just a simple data upload as you can add any other business logic here
}
use Dandysi\Laravel\BatchUpload\Services\BatchService;
//Step 1 - Create
$service = app(BatchService::class);
$options = $service->options('create_categories', '/data/categories.csv');
$batch = $service->create($options);
//Step 2 - Approve
$batch->status = Batch::STATUS_APPROVE;
$batch->save();
//Step 3 - Dispatch (each row will be a seperate queued job)
$service->dispatch($batch);