PHP code example of akika / laravel-exporter

1. Go to this page and download the library: Download akika/laravel-exporter 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/ */

    

akika / laravel-exporter example snippets




namespace App\Exports;

use Akika\LaravelExporter\Concerns\InteractsWithExportOptions;
use Akika\LaravelExporter\Contracts\Exportable;
use App\Models\Purchase;
use Illuminate\Database\Eloquent\Builder;

class PurchasesExport implements Exportable
{
    use InteractsWithExportOptions;

    public function query(): Builder
    {
        return Purchase::query()
            ->when(
                $this->option('store_id'),
                fn (Builder $query, $storeId) =>
                    $query->where('store_id', $storeId)
            )
            ->orderBy('id');
    }

    public function headings(): array
    {
        return [
            'ID',
            'Reference',
            'Amount',
            'Created At',
        ];
    }

    public function map(mixed $purchase): array
    {
        return [
            $purchase->id,
            $purchase->reference,
            $purchase->amount,
            $purchase->created_at?->toDateTimeString(),
        ];
    }

    public function validateOptions(): void
    {
        //
    }
}

public function validateOptions(): void
{
    validator(
        $this->options(),
        [
            'store_id' => [
                'nullable',
                'integer',
            ],
            'from' => [
                'nullable',
                'date',
            ],
            'to' => [
                'nullable',
                'date',
                'after_or_equal:from',
            ],
        ]
    )->validate();
}

use Akika\LaravelExporter\Facades\Exporter;
use App\Exports\PurchasesExport;

$export = Exporter::make(PurchasesExport::class)
    ->name('Purchases')
    ->for(auth()->user())
    ->with([
        'store_id' => 12,
    ])
    ->queue();

$export = Exporter::make(PurchasesExport::class)
    ->with([
        'store_id' => 12,
        'from' => '2026-09-01',
        'to' => '2026-09-30',
    ])
    ->queue();

$storeId = $this->option('store_id');

$storeId = $this->option(
    'store_id',
    null
);

$export = Exporter::make(PurchasesExport::class)
    ->for(auth()->user())
    ->queue();

$export = Exporter::make(PurchasesExport::class)
    ->for(auth()->user())
    ->with([
        'store_id' => 12,
    ])
    ->unique()
    ->queue();

$export->refresh();

$export->status;
$export->processed_rows;
$export->total_rows;
$export->progress;
$export->remaining_rows;

if ($export->isProcessing()) {
    echo "{$export->progress}%";
}

$export->isPending();
$export->isProcessing();
$export->isCompleted();
$export->isFailed();
$export->isCancelled();
$export->isActive();
$export->isFinished();

use Akika\LaravelExporter\Models\Export;

$exports = Export::query()
    ->forOwner(auth()->user())
    ->latest()
    ->paginate();

Export::query()->pending();
Export::query()->processing();
Export::query()->active();
Export::query()->completed();
Export::query()->failed();
Export::query()->cancelled();
Export::query()->finished();
Export::query()->expired();

$exports = Export::query()
    ->forOwner(auth()->user())
    ->completed()
    ->latest()
    ->paginate();

$export->cancel();

$url = $export->downloadUrl();

$url = $export->

use Akika\LaravelExporter\Events\ExportCompleted;
use Illuminate\Support\Facades\Event;

Event::listen(
    ExportCompleted::class,
    function (ExportCompleted $event) {
        // Handle completed export.
    }
);

use Illuminate\Support\Facades\Schedule;

Schedule::command('exporter:prune')
    ->daily();

use Akika\LaravelExporter\Models\Export;

$exports = Export::query()
    ->forOwner(auth()->user())
    ->active()
    ->get();

[
    'web',
    'auth',
]

use Akika\LaravelExporter\Exceptions\ExporterException;

try {
    $export = Exporter::make(PurchasesExport::class)
        ->queue();
} catch (ExporterException $exception) {
    // Handle exporter-specific errors.
}
bash
php artisan vendor:publish --tag=exporter-config
text
config/exporter.php
bash
php artisan vendor:publish --tag=exporter-migrations
bash
php artisan migrate
text
config/exporter.php
bash
php artisan exporter:prune
bash
php artisan queue:work
bash
php artisan queue:work --queue=exports
bash
composer dump-autoload