Skip to content

Instantly share code, notes, and snippets.

@mnshankar
mnshankar / routes.php
Last active June 13, 2017 19:02 — forked from coreymcmahon/routes.php
Using macros to implement custom response types in Laravel - www.slashnode.com
<?php
Response::macro('csv', function($data, $filename = 'data.csv', $status = 200, $delimiter = ",", $linebreak = "\n", $headers = array())
{
return Response::stream(function () use ($data, $delimiter, $linebreak) {
foreach ($data as $row) {
$keys = array(); $values = array();
$firstPassComplete = (isset($firstPassComplete)) ? true:false;
foreach ($row as $k => $v) {
if (!$firstPassComplete){