Skip to content

Instantly share code, notes, and snippets.

@AlbinoDrought
Created August 15, 2017 18:08
Show Gist options
  • Save AlbinoDrought/669db99dccd479f85cead7a25f7bee0a to your computer and use it in GitHub Desktop.
Save AlbinoDrought/669db99dccd479f85cead7a25f7bee0a to your computer and use it in GitHub Desktop.
Nullable Laravel JSON response
<?php
namespace App\Http\Responses;
use Illuminate\Http\JsonResponse;
class NullableJsonResponse extends JsonResponse
{
public function __construct($data = null, $status = 200, array $headers = [], $options = 0)
{
parent::__construct($data, $status, $headers, $options);
if ($data === null) {
$this->setData(null);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment