PHP code example of netsells / csvme
1. Go to this page and download the library: Download netsells/csvme 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/ */
netsells / csvme example snippets
$csv = new Csvme();
$csv->withHeader(['ID', 'Total', 'Number of Items', 'Created At'])
->withLayout(function(Order $order) {
return [
$order->id,
$order->total,
$order->items->count(),
$order->created_at->format('d-m-Y'),
];
})
->withItems($orders)
->output();
$csv = new Csvme();
$csv->output(new OrderExportComposer($orders));
use Netsells\Csvme\Csvme;
use Netsells\Csvme\CsvComposer;
class OrderExportComposer implements CsvComposer
{
/**
* The orders.
*
* @var array
*/
protected $orders;
/**
* Create a new csv composer.
*
* @param array $orders
* @return void
*/
public function __construct($orders)
{
$this->orders = $orders;
}
/**
* Configure the CSV
*
* @param Csvme $csv
* @return void
*/
public function compose(Csvme $csv)
{
$csv->withHeader(['ID', 'Total', 'Number of Items', 'Created At'])
->withLayout(function(Order $order) {
return [
$order->id,
$order->total,
$order->items->count(),
$order->created_at->format('d-m-Y'),
];
})
->withItems($this->orders);
}
}
$csv = new Csvme();
$csv->withHeader(['ID', 'Total', 'Number of Items', 'Created At'])
->withLayout(function(Order $order) {
return [
$order->id,
$order->total,
$order->items->count(),
$order->created_at->format('d-m-Y'),
];
})
->withItems($orders)
->setCorsHeader('https://test.com')
->output();