PHP code example of zegitz / laravel-csv-response

1. Go to this page and download the library: Download zegitz/laravel-csv-response library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

zegitz / laravel-csv-response example snippets


$data = [
    ['first_name', 'last_name'],
    ['John', 'Doe'],
    ['Jane', 'Doe'],
];

return response()->csv($data);

Zegitz\Routing\ResponseFactoryServiceProvider::class,

response()->csv(collect(
    new User(['first_name' => 'John', 'last_name' => 'Doe']),
    new User(['first_name' => 'Jane', 'last_name' => 'Doe']),
));

response()->csv([
    ['first_name', 'last_name'],
    ['John', 'Doe'],
    ['Jane', 'Doe'],
]);

response()->csv([
    ['first_name' => 'John', 'last_name' => 'Doe'],
    ['first_name' => 'Jane', 'last_name' => 'Doe'],
]);

response()->csv("first_name;last_name\r\nJohn;Doe\r\nJane;Doe");

class User
{
    public function csvSerialize()
    {
        return [
            'first_name' => $this->first_name,
            'last_name' => $this->last_name,
        ];
    }
}

public function csv($data, $status = 200, array $headers = [], array $options = [])

[
    'Content-Type' => 'text/csv; charset=WINDOWS-1252',
    'Content-Encoding' => 'WINDOWS-1252',
    'Content-Transfer-Encoding' => 'binary',
    'Content-Description' => 'File Transfer',
]

[
    'encoding' => 'WINDOWS-1252',
    'delimiter' => ';',
    'quoted' => true,
    '