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/ */

    

dandysi / laravel-batch-upload example snippets


/**
 * Register processors here
 */
'processors' => [
    App\BatchUploads\CreateCategoriesProcessor::class
],

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);


$options = $service
    ->options('create_categories', '/data/categories.csv')
    ->schedule(now()->tommorow())
;

class Kernel extends ConsoleKernel
{
    /**
     * Define the application's command schedule.
     */
    protected function schedule(Schedule $schedule): void
    {
        $schedule->command('batch-upload:dispatch')->everyTenMinutes();
    }

$options = $service
    ->options('create_categories', '/data/categories.csv')
    ->user('user123')
;
bash
php artisan vendor:publish --provider="Dandysi\Laravel\BatchUpload\BatchUploadServiceProvider"
bash
php artisan make:batch-upload-processor CreateCategoriesProcessor create_categories
bash
php artisan batch-upload:dispatch
bash
php artisan batch-upload:create create_categories /data/categories.csv --force-dispatch