Created
November 9, 2017 17:03
-
-
Save hskrasek/ce3d67266cc8e1195b340f6d1175715a to your computer and use it in GitHub Desktop.
Sunset Laravel
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 | |
class APIController | |
{ | |
uses SunsetsEndpoints; | |
public function index() | |
{ | |
return $this->sunsetResponse($apiResponse, 'really cool date here'); | |
} | |
} |
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 | |
trait SunsetsEndpoints | |
{ | |
/** | |
* @return \Illuminate\Http\Response | |
*/ | |
public function sunsetResponse(Response $response, $date, $link = null): Response | |
{ | |
return tap($response, function (Response $response) use ($date, $link) { | |
$response->headers->add('Sunset', $date); | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment