Skip to content

Instantly share code, notes, and snippets.

@jorijn
Created September 13, 2012 08:30
Show Gist options
  • Save jorijn/3712880 to your computer and use it in GitHub Desktop.
Save jorijn/3712880 to your computer and use it in GitHub Desktop.
Laravel paste
Route::filter('after', function($response)
{
if (($requested_type = Input::get('datagrid_download_as', false)) !== false && isset($response->content->data['datagrid']))
{
$original_datagrid = $response->content->data['datagrid'];
$requested_class = '\\UI\\DataGrid\\'.strtoupper($requested_type);
if (class_exists($requested_class) === false)
{
// return the original response, we have no point on
// going any further.
return $response;
}
else
{
// ok! copy the data into the new me.
$datagrid = new $requested_class;
$datagrid->columns = $original_datagrid->columns;
$datagrid->data = $original_datagrid->data;
// write it down.
file_put_contents(($file_location = tempnam()), $datagrid->render(true));
// return the new laravel response
return Response::download($file_location, 'export.'.strtolower($requested_type));
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment