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
{
//
}
}