Skip to content

Instantly share code, notes, and snippets.

@sahilkashyap64
Created June 9, 2021 08:15
Show Gist options
  • Save sahilkashyap64/685f8757e5dd3be34ac548800f28ccca to your computer and use it in GitHub Desktop.
Save sahilkashyap64/685f8757e5dd3be34ac548800f28ccca to your computer and use it in GitHub Desktop.
Laravel Use gzencode compression in rest api
Route::get('channeldayschdeule', 'DemoController@channelDaysSchedule');
public function channelDaysSchedule() {
$record= DB::table('gracenote'); //use select to limit data
$reco=$record->get();
$response = [
'success' => true,
'date'=>date("Y-m-d"),
// 'count' => $reco->count(),
'data' => $reco,
'message' => 'Schedule data for 3 days found',
'response_code'=>200,
];
$responsejson=json_encode($response);
$data=gzencode($responsejson,9);
return response($data)->withHeaders([
'Access-Control-Allow-Origin' => '*',
'Access-Control-Allow-Methods'=> 'GET',
'Content-type' => 'application/json; charset=utf-8',
'Content-Length'=> strlen($data),
'Content-Encoding' => 'gzip'
]);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment