Skip to content

Commit

Permalink
fix(api-response-facade): Add castToNull method declaration
Browse files Browse the repository at this point in the history
- Introduce the castToNull() method to the ApiResponseFacade.
- This method provides a way to handle null casting in API responses.
- Enhances the functionality of the facade for better type handling.
  • Loading branch information
guanguans committed Nov 8, 2024
1 parent 2a87ece commit 375f612
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/Facades/ApiResponseFacade.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
* @method static \Guanguans\LaravelApiResponse\ApiResponse castToBoolean()
* @method static \Guanguans\LaravelApiResponse\ApiResponse castToFloat()
* @method static \Guanguans\LaravelApiResponse\ApiResponse castToInteger()
* @method static \Guanguans\LaravelApiResponse\ApiResponse castToNull()
* @method static \Guanguans\LaravelApiResponse\ApiResponse castToObject()
* @method static \Guanguans\LaravelApiResponse\ApiResponse castToString()
* @method static \Illuminate\Http\JsonResponse conflict(string $message = '')
Expand Down
4 changes: 3 additions & 1 deletion src/Pipes/CallableDataPipe.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ public function handle(array $structure, \Closure $next): JsonResponse
*/
private function dataFor($data)
{
return \is_callable($data) && !(\is_string($data) && \function_exists($data)) ? $data() : $data;
return \is_callable($data) && !(\is_string($data) && \function_exists($data))
? $data()
: $data;
}
}

0 comments on commit 375f612

Please sign in to comment.