Skip to content

Commit f02f00a

Browse files
committed
Add `self` return type for `setDefaultSuccessResponse()`, update read me wording.
1 parent 3bf5825 commit f02f00a

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

README.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,11 +78,12 @@ Returns a `201` HTTP status code, with response optional data
7878

7979
Returns a `204` HTTP status code, with optional response data. Strictly speaking, the response body should be empty. However, functionality to optionally return data was added to handle legacy projects. Within your own projects, you can simply call the method, omitting parameters, to generate a correct `204` response i.e. `return $this->respondNoContent()`
8080

81-
#### `setDefaultSuccessResponse(?array $content = null)`
81+
#### `setDefaultSuccessResponse(?array $content = null): self`
8282

83-
Allows to replace default `['success' => true]` response returned by `respondWithSuccess` with `$content`. You can call it in constructor to change default for all calls or call it in place where you need it. This is a fluent method returning `$this` which lets you chain calls.
83+
Optionally, replace the default `['success' => true]` response returned by `respondWithSuccess` with `$content`. This method can be called from the constructor (to change default for all calls), a base API controller or place when required.
84+
85+
`setDefaultSuccessResponse` is a fluent method returning `$this` allows for chained methods calls:
8486

85-
Example:
8687
```php
8788
$users = collect([10, 20, 30, 40]);
8889

@@ -95,7 +96,9 @@ public function __construct()
9596
{
9697
$this->setDefaultSuccessResponse([]);
9798
}
99+
98100
...
101+
99102
$users = collect([10, 20, 30, 40]);
100103

101104
return $this->respondWithSuccess($users);

src/ApiResponseHelpers.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414

1515
trait ApiResponseHelpers
1616
{
17-
1817
private ?array $_api_helpers_defaultSuccessData = ['success' => true];
1918

2019
/**
@@ -47,7 +46,7 @@ public function respondWithSuccess($contents = null): JsonResponse
4746
return $this->apiResponse($data);
4847
}
4948

50-
public function setDefaultSuccessResponse(?array $content = null)
49+
public function setDefaultSuccessResponse(?array $content = null): self
5150
{
5251
$this->_api_helpers_defaultSuccessData = $content ?? [];
5352
return $this;

0 commit comments

Comments
 (0)