Skip to content

Instantly share code, notes, and snippets.

@bayleedev
Created October 16, 2012 03:02
Show Gist options
  • Save bayleedev/3897032 to your computer and use it in GitHub Desktop.
Save bayleedev/3897032 to your computer and use it in GitHub Desktop.
Rewrite response in laravel
<?php
Route::filter('after', function($response)
{
$params = \Laravel\Request::$route->parameters;
// The 'type' is the last param
// example: /product/(:num).(:any)
$type = array_pop($params);
if($type == 'json') {
$res = Response::json($response->content->data);
foreach($response as $key => &$value) {
$response->$key = $res->$key;
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment