Skip to content

Commit 2100604

Browse files
committed
clean response api
1 parent 1c5915a commit 2100604

File tree

3 files changed

+14
-10
lines changed

3 files changed

+14
-10
lines changed

README.md

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ With easy repository, you can have the power of the repository pattern, without
44

55
## Requirement
66

7-
- Minimum PHP ^8.1
7+
- Minimum PHP ^8.2
88

99
## Installation
1010

@@ -17,9 +17,13 @@ Specific Version :
1717

1818
| Laravel Version | Package Version |
1919
|:---------------:|:------------------:|
20-
| 10 | 4.x |
20+
| 11 | 5.x |
21+
| 10 | 4.0 |
2122
| 9 | 3.2 |
2223
```bash
24+
# for laravel 10
25+
$ composer require yaza/laravel-repository-service:"^4.0"
26+
# for laravel 9
2327
$ composer require yaza/laravel-repository-service:"^3.2"
2428
```
2529

@@ -50,8 +54,8 @@ php artisan make:service UserService
5054
// or
5155
php artisan make:service UserService --repository
5256

53-
// create service for api template
54-
php artisan make:service UserService --api
57+
// create service with blank template
58+
php artisan make:service UserService --blank
5559

5660
```
5761

src/Traits/Response.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,19 +17,19 @@ trait Response
1717
* @param null $code
1818
* @return \Illuminate\Http\JsonResponse
1919
*/
20-
public function responseJson($msg = '', $data = [], $code = null, $errors = [])
20+
public function responseJson($msg = '', $data = [], $code = null, $errors = null)
2121
{
2222
if(is_null($code)){
2323
$http_code = 200;
2424
}else{
2525
$http_code = $code;
2626
}
2727

28-
return response()->json([
28+
return response()->json(array_filter([
2929
'code' => $http_code,
3030
'message' => $msg,
3131
'data' => $data,
3232
'errors' => $errors
33-
], $http_code);
33+
]), $http_code);
3434
}
3535
}

src/Traits/ResultService.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ trait ResultService
1313
private $data = null;
1414
private $message = null;
1515
private $code = null;
16-
private $errors = [];
16+
private $errors = null;
1717

1818
/**
1919
* set data output
@@ -149,11 +149,11 @@ public function toJson()
149149
$http_code = $this->getCode();
150150
}
151151

152-
return response()->json([
152+
return response()->json(array_filter([
153153
'code' => $http_code,
154154
'message' => $this->getMessage(),
155155
'data' => $this->getData(),
156156
'errors' => $this->getError(),
157-
], $http_code);
157+
]), $http_code);
158158
}
159159
}

0 commit comments

Comments
 (0)