Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

kristovnovok1's avatar

How to get Laravel Excel data export like this ?

Hello.

I have array like this. I want to change this array so I can export in different format. I want to group the companies distinctly as each row and group dates across top as headings (I have array item for every day in the week). This is array at this moment.

return [
    [
        'company_id' => 1,
        'company_name' => 'ABC Corp',
        'start' => '2021-09-27',
        'end' => '2021-09-27',
        'staff' => [
            [
                'name' => 'Jared',
                'age' => 32
            ],
            [
                'name' => 'Vladimir',
                'age' => 44
            ],            
        ]
    ],
    [
        'company_id' => 1,
        'company_name' => 'ABC Corp',
        'start' => '2021-09-28',
        'end' => '2021-09-28',
        'staff' => [
            [
                'name' => 'Jenifer',
                'age' => 19
            ],
            [
                'name' => 'Woijiec',
                'age' => 30
            ],            
        ]
    ],
    [
        'company_id' => 99,
        'company_name' => 'HBO Inc',
        'start' => '2021-09-27',
        'end' => '2021-09-27',
        'staff' => [
            [
                'name' => 'Pablo',
                'age' => 27
            ],
            [
                'name' => 'Reinir',
                'age' => 40
            ],            
        ]
    ],
    [
        'company_id' => 99,
        'company_name' => 'HBO Inc',
        'start' => '2021-09-28',
        'end' => '2021-09-28',
        'staff' => [
            [
                'name' => 'Anjun',
                'age' => 30
            ],
            [
                'name' => 'David',
                'age' => 28
            ],            
        ]
    ],
]

I want export something to look like this. Can anyone help me with this?

https ://ibb.co/BgPYB62

0 likes
1 reply

Please or to participate in this conversation.