PHP code example of nghia-kun / laravel-file-export
1. Go to this page and download the library: Download nghia-kun/laravel-file-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/ */
nghia-kun / laravel-file-export example snippets
use NghiaKun\FileExport\Export\BaseExport;
class UserExport extends BaseExport
{
public function query()
{
return User::query();
}
public function headings(): array
{
return ['id', 'name', 'email'];
}
public function map($user): array
{
return [$user->id, $user->name, $user->email];
}
}
use NghiaKun\FileExport\Export\ExportService;
// Xuất ra 1 file .tsv
(new ExportService(new UserExport(), storage_path('app/users.tsv'), 'tsv'))->handle();
// Xuất ra 1 file .zip chứa nhiều file .tsv (chia theo recordsPerFile)
(new ExportService(new UserExport(), storage_path('app/users.zip'), 'zip'))->handle();
use NghiaKun\FileExport\Compress\ZipService;
(new ZipService())->compressFolder($sourceDir, $zipDestination, true);