Skip to content

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
adrianzofcin authored Jan 19, 2023
1 parent 2e436e1 commit bd31925
Showing 1 changed file with 22 additions and 11 deletions.
33 changes: 22 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,15 @@ 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:

```json
{
"data": null,
"code": "1.1.1",
"code": "1.2",
"errors": null,
"message": "Hello"
}
Expand All @@ -67,26 +67,37 @@ 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:

```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:
Expand All @@ -97,7 +108,7 @@ Response:
"id": 1,
"name": "Jhon Jhonson"
},
"code": "1.1.1",
"code": "1.2",
"errors": null,
"message": "Hello"
}
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -187,8 +198,8 @@ Response:
"to": 2,
"total": 6
},
"code": "1.2.1",
"code": "1.2",
"errors": null,
"message": "Hello"
}
```
```

0 comments on commit bd31925

Please sign in to comment.