1. Go to this page and download the library: Download akki/bulkexportcsv 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/ */
/** @file config/bulkexportcsv.php */
return [
/*
* Number of Records to be fetched per job
*/
'records_per_job' => 10000,
/*
* records will be fetched in chunks for better performance
*/
'chunks_of_records_per_job' => 2,
/*
* Directory where CSV will be prepared inside storage folder
*/
'dir' => 'app/public/exportCSV',
/*
* Database connection for bulk_export_csv table
*/
'db_connection' => env('DB_CONNECTION', 'mysql'),
/*
* Queue connection for jobs
*/
'queue_connection' => env('QUEUE_CONNECTION', 'database'),
/*
* Name of queue where job will be dispatched
*/
'queue' => 'default',
/*
* Name of queue job batch
*/
'batch_name' => 'Bulk Export CSV',
/*
* The number of seconds the job can run before timing out
* null takes default value
* The pcntl PHP extension must be installed in order to specify job timeouts
*/
'job_timeout' => null,
/*
* if any job fails, it stops CSV preparation process
* Decide whether partial CSV prepared should get deleted or not
*/
'delete_csv_if_job_failed' => false
];
[
'jobs_id' => unique ID generated for an export CSV request
'csv_name' => CSV file name
'total_records' => total number of records exported
'total_jobs' => total jobs ' => export status of CSV as 'InProgress', 'Completed', 'Error' or 'Cancelled'
'each_jobs_time' => time taken by each job processed
'average_jobs_time' => average time all jobs taken
'error' => Exception error if any job fails or 'BulkExportCSVSucceeded' or 'BulkExportCSVFailed' events threw exception
'config' => bulk export configuration used for an export CSV request
'user_id' => ID of auth user requesting export CSV
'batch_id' => batch_id of job batching process
]
$user = auth()->user();
$data = ['user' => $user, 'request' => $request->all(), 'csv_info' => 'Toal Users on Platform'];
$columns = []; //if columns are defined as empty, then columns will be taken from json resource itself
$bulkExportCSV = \BulkExportCSV::build($query, $resource_namespace, $columns, $data);
// regiser service provider
$app->register(Akki\BulkExportCSV\ServiceProvider::class);
// Enable Facades
$app->withFacades();
// Enable Eloquent
$app->withEloquent();
// Enable bulk export configuration
$app->configure('bulkexportcsv');
// BulkExportCSV class alias
if (!class_exists('BulkExportCSV')) {
class_alias('Akki\\BulkExportCSV\\Facades\\BulkExport', 'BulkExportCSV');
}
// EloquentSerialize class alias
if (!class_exists('EloquentSerialize')) {
class_alias('AnourValar\EloquentSerialize\Facades\EloquentSerializeFacade', 'EloquentSerialize');
}
$app = new Laravel\Lumen\Application(
dirname(__DIR__)
);
// declare path to storage folder
$app->instance('path.storage', app()->basePath() . DIRECTORY_SEPARATOR . 'storage');
public function register()
{
$this->app->singleton(\Illuminate\Contracts\Routing\ResponseFactory::class, function() {
return new \Laravel\Lumen\Http\ResponseFactory();
});
}