It seems like you're trying to include multiple header rows in your Excel export using the Maatwebsite/Excel package. The code you've provided should work for multiple headers as long as both $header2 and $header3 are defined and returned as an array of arrays from the headings method.
Here's a revised version of your headings method that should work for multiple headers:
use Maatwebsite\Excel\Concerns\FromArray;
use Maatwebsite\Excel\Concerns\FromCollection;
use Maatwebsite\Excel\Concerns\WithHeadings;
class CombinedConfidentialsExport implements FromArray, WithHeadings
{
public function headings(): array
{
$header2 = [
// ... your header2 values here
];
$header3 = [
// ... your header3 values here
];
return [
$header2,
$header3,
];
}
}
Make sure that both $header2 and $header3 are properly defined arrays before returning them. If you're still facing issues, here are a few troubleshooting steps:
- Check for Errors: Make sure there are no syntax errors or typos in your code.
-
Debugging: Add
dd($header2, $header3);right before thereturnstatement to dump the headers and ensure they are what you expect. - Package Version: Ensure you are using a version of the Maatwebsite/Excel package that supports multiple headers. If you're using an older version, consider updating.
- Documentation: Review the official documentation for any updates or changes in how to handle multiple headers.
If you've followed these steps and are still encountering issues, please provide more context or any error messages you're receiving, and I'll be happy to help you further.