Brandon.css's avatar

Laravel Save Array to CSV in Storage

I'm trying to save an array to a csv file in my storage. I setup a new filesystem for local storage to a app/csv folder, and have this code:

        $productItemNumbers = [0, 15, 158, 584];
        $exportFileName     = sprintf('products-%s.csv', date('d-m-Y'));
        Storage::disk('csv')->put($exportFileName, $productItemNumbers);

However, it's saving all the array items to a single column. Is there a better way to do this so each array item is its own row?

0 likes
2 replies
jlrdw's avatar
jlrdw
Best Answer
Level 75

You'd have to Loop and store one line at a time.

Please or to participate in this conversation.