Save to Path an Eloquent Collection to a CSV with League CSV
15:31 15 Oct 2019

I have this function that export the csv, the it outputs the file so the user can download it.

 public function export()
{
    $people = Person::all();

    $csv = \League\Csv\Writer::createFromFileObject(new \SplTempFileObject());

    $csv->insertOne(\Schema::getColumnListing('people'));

    foreach ($people as $person) {
        $csv->insertOne($person->toArray());
    }

    $csv->output('people.csv');
}

Instead of this I want to save the file in a project folder.

how could i do it?

thanks

php laravel csv thephpleague-csv