Skip to content

Commit 2bc9ba7

Browse files
committed
Initial commit
0 parents  commit 2bc9ba7

File tree

2 files changed

+45
-0
lines changed

2 files changed

+45
-0
lines changed

composer.json

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"name": "code-creeper/respondo",
3+
"description": "This is a simple package containing a simple trait for json response with specific formate.",
4+
"license": "MIT",
5+
"require": {
6+
"php": "^5.4"
7+
},
8+
"autoload": {
9+
"psr-4": {
10+
"CodeCreeper\\Respondo\\": "src/"
11+
}
12+
},
13+
"minimum-stability": "stable",
14+
"require": {}
15+
}

src/ResponseMethods.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
3+
namespace CodeCreeper\Respondo;
4+
5+
trait ResponseMethods
6+
{
7+
protected function sendError($errorMessages = 'Something went wrong, internal server error.', $code = 500, $result = [])
8+
{
9+
$response = [
10+
'metadata' => [
11+
'message' => $errorMessages,
12+
],
13+
'payload' => $result,
14+
];
15+
16+
return response()->json($response, $code);
17+
}
18+
19+
protected function sendResponse($result, $message = '', $code = 200)
20+
{
21+
$response = [
22+
'metadata' => [
23+
'message' => $message,
24+
],
25+
'payload' => $result,
26+
];
27+
28+
return response()->json($response, $code);
29+
}
30+
}

0 commit comments

Comments
 (0)