Does that dd() trigger?
Dec 14, 2021
7
Level 2
Laravel Excel - Mapping Doesn't Bring Any Data (Doesn't Work)
Hello forks! I am using the Laravel Excel package to export a list of transactions with the relationships. In the example below, I have used two methods ('headings' and 'map'). When I export, I receive the data for headings but no data for mapping. Please help me, folks. Thank you so much in advance.
Export / TransactionsExport.php
<?php
namespace App\Exports;
use App\Models\Transaction;
use Maatwebsite\Excel\Concerns\WithMapping;
use Maatwebsite\Excel\Concerns\WithHeadings;
class TransactionsExport implements WithHeadings, WithMapping
{
/**
* @var Transaction $transaction
*/
public function map($transaction): array
{
dd('work?');
return [
$transaction->invoice_no,
$transaction->tenant->name,
$transaction->end_date,
];
}
public function headings(): array
{
return [
'Invoice No.',
'Tenant Name',
'End Date',
];
}
}
TransactionController.php
use App\Exports\TransactionsExport;
// Export as excel
public function export() {
return Excel::download(new TransactionsExport, 'transactions.xlsx');
}
Level 102
And where should the data come from? I dont see you passing in any data to the export?
https://docs.laravel-excel.com/3.1/exports/collection.html or https://docs.laravel-excel.com/3.1/exports/from-query.html
1 like
Please or to participate in this conversation.