Skip to content

Instantly share code, notes, and snippets.

View aglipanci's full-sized avatar

Agli Pançi aglipanci

View GitHub Profile
@aglipanci
aglipanci / ExportableCollections.php
Created March 7, 2022 17:36
Exportable Collections using maatwebsite/excel
<?php
Collection::macro('export', function (string $filename, array $headers = []) {
return (new class($this, $headers) implements FromCollection, WithHeadings{
use Exportable;
public function __construct(
private \Illuminate\Support\Collection|\Illuminate\Database\Eloquent\Collection $collection,
private array $headings = []
) {