Skip to content

Instantly share code, notes, and snippets.

@maxwellimpact
Created January 13, 2019 16:31
Show Gist options
  • Save maxwellimpact/9b57976a77ef389590ff1927bb37bdf8 to your computer and use it in GitHub Desktop.
Save maxwellimpact/9b57976a77ef389590ff1927bb37bdf8 to your computer and use it in GitHub Desktop.
Simple helper for standard rest API Responses
<?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