Created
January 13, 2019 16:31
-
-
Save maxwellimpact/9b57976a77ef389590ff1927bb37bdf8 to your computer and use it in GitHub Desktop.
Simple helper for standard rest API Responses
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 | |
use Illuminate\Http\Response; | |
trait ApiResponsable | |
{ | |
protected function view($data = []) | |
{ | |
return response()->json($data); | |
} | |
protected function created($data = []) | |
{ | |
return response()->json($data, Response::HTTP_CREATED); | |
} | |
protected function updated($data = []) | |
{ | |
return empty($data) ? response()->noContent() : $this->view($data); | |
} | |
protected function destroyed() | |
{ | |
return response()->noContent(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment