From bd319255954e58534fcd383fc410e576431a3133 Mon Sep 17 00:00:00 2001 From: adrianzofcin <75702986+fetaciik@users.noreply.github.com> Date: Thu, 19 Jan 2023 11:49:59 +0100 Subject: [PATCH] Update README.md --- README.md | 33 ++++++++++++++++++++++----------- 1 file changed, 22 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index decaf51..a6b12f8 100644 --- a/README.md +++ b/README.md @@ -48,7 +48,7 @@ Response: You can pass internal code using `code()` function that helps you find of response in case of error. ```php -return ApiResponse::code('1.2.1')->message('Hello')->response(201); +return ApiResponse::code('1.2')->message('Hello')->response(201); ``` Response: @@ -56,7 +56,7 @@ Response: ```json { "data": null, - "code": "1.1.1", + "code": "1.2", "errors": null, "message": "Hello" } @@ -67,9 +67,9 @@ If you don't use `message()` function but use `code()` function, and it will try You can also set prefix of translation as second parameter *(Default is 'api')*. ```php -return ApiResponse::code('1.2.1', 'user')->response(201); // return "message": "user.1.1.1" as in Response example +return ApiResponse::code('1.2', 'user')->response(201); // return "message": "user.1.2" as in Response example -return ApiResponse::code('1.2.1')->response(201); // When not presented second parameter it will use default and return "message": "api.1.1.1" +return ApiResponse::code('1.2')->response(201); // When not provided second parameter it will use default and return "message": "api.1.2" ``` Response: @@ -77,16 +77,27 @@ Response: ```json { "data": null, - "code": "1.1.1", + "code": "1.2", "errors": null, - "message": "user.1.1.1" + "message": "user.1.2" +} +``` + +When not provided second parameter + +```json +{ + "data": null, + "code": "1.2", + "errors": null, + "message": "api.1.2" } ``` You can pass data using `data()` function. ```php -return ApiResponse::data(['id' => 1, 'name' => 'Jhon Jhonson'])->code('1.2.1')->message('Hello')->response(201); +return ApiResponse::data(['id' => 1, 'name' => 'Jhon Jhonson'])->code('1.2')->message('Hello')->response(201); ``` Response: @@ -97,7 +108,7 @@ Response: "id": 1, "name": "Jhon Jhonson" }, - "code": "1.1.1", + "code": "1.2", "errors": null, "message": "Hello" } @@ -128,7 +139,7 @@ You can use this function by passing paginated data, and you can also pass Resou ```php $users = User::paginate(10); -return ApiResponse::collection($users, UserResource::class)->code('1.2.1')->message('Hello')->response(201); +return ApiResponse::collection($users, UserResource::class)->code('1.2')->message('Hello')->response(201); ``` Response: @@ -187,8 +198,8 @@ Response: "to": 2, "total": 6 }, - "code": "1.2.1", + "code": "1.2", "errors": null, "message": "Hello" } -``` \ No newline at end of file +```