Created
August 15, 2017 18:08
-
-
Save AlbinoDrought/669db99dccd479f85cead7a25f7bee0a to your computer and use it in GitHub Desktop.
Nullable Laravel JSON response
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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