Skip to content

Commit e18bf23

Browse files
committed
fix: backward compatibility
1 parent a48c61c commit e18bf23

File tree

1 file changed

+67
-6
lines changed

1 file changed

+67
-6
lines changed

src/Traits/ResultService.php

Lines changed: 67 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,57 @@ trait ResultService
1414
private $message = null;
1515
private $code = null;
1616
private $errors = null;
17+
/**
18+
* @deprecated version
19+
*/
20+
private $status = null;
21+
22+
/**
23+
* set status
24+
* @deprecated version
25+
* @param $status
26+
* @return $this
27+
*/
28+
public function setStatus($status)
29+
{
30+
$this->status = $status;
31+
32+
return $this;
33+
}
34+
35+
/**
36+
* get status
37+
* @deprecated version
38+
* @return bool
39+
*/
40+
public function getStatus()
41+
{
42+
return $this->status;
43+
}
44+
45+
46+
/**
47+
* set result output
48+
* @deprecated version
49+
* @param $result
50+
* @return $this
51+
*/
52+
public function setResult($result)
53+
{
54+
$this->data = $result;
55+
56+
return $this;
57+
}
58+
59+
/**
60+
* get result
61+
* @deprecated version
62+
* @return null
63+
*/
64+
public function getResult()
65+
{
66+
return $this->data;
67+
}
1768

1869
/**
1970
* set data output
@@ -149,11 +200,21 @@ public function toJson()
149200
$http_code = $this->getCode();
150201
}
151202

152-
return response()->json(array_filter([
153-
'code' => $http_code,
154-
'message' => $this->getMessage(),
155-
'data' => $this->getData(),
156-
'errors' => $this->getError(),
157-
]), $http_code);
203+
if($this->status !== null) {
204+
return response()->json(array_filter([
205+
'success' => $this->getStatus(),
206+
'code' => $http_code,
207+
'message' => $this->getMessage(),
208+
'data' => $this->getData(),
209+
'errors' => $this->getError(),
210+
]), $http_code);
211+
} else {
212+
return response()->json(array_filter([
213+
'code' => $http_code,
214+
'message' => $this->getMessage(),
215+
'data' => $this->getData(),
216+
'errors' => $this->getError(),
217+
]), $http_code);
218+
}
158219
}
159220
}

0 commit comments

Comments
 (0)