Skip to content

Instantly share code, notes, and snippets.

@jadjoubran
Last active August 27, 2016 10:32
Show Gist options
  • Save jadjoubran/0905e223e37657427d4b8c6573ab0ee0 to your computer and use it in GitHub Desktop.
Save jadjoubran/0905e223e37657427d4b8c6573ab0ee0 to your computer and use it in GitHub Desktop.
Laravel Response Macro - Original PostsController.php
<?php
use App\Post;
class PostsController
{
public function get()
{
try {
//some code
}catch (Exception $e){
//error
return [
'errors' => true,
'message' => $e->getMessage()
];
}
$posts = Post::get();
//success
return [
'errors' => false,
'data' => compact('posts')
];
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment