Skip to content

Commit

Permalink
Merge pull request #13 from TheDragonCode/2.x
Browse files Browse the repository at this point in the history
Update `README.md`
  • Loading branch information
Andrey Helldar authored Feb 11, 2022
2 parents 4843e50 + ec7b51d commit b79852d
Showing 1 changed file with 2 additions and 10 deletions.
12 changes: 2 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,8 @@ Or manually update `require` block of `composer.json` and run `composer update`.

After you've installed the package via composer, you're done. There's no step two.

This package will automatically register the `DragonCode\LaravelJsonResponse\Middlewares\SetHeaderMiddleware` middleware in the `web` and `api` groups, if they
exist. The middleware will add a header `Accept` that will effectively convert all responses to JSON format. This header will apply to all responses.

## Troubleshooting

> Why are my error messages not being converted to JSON?
This is a feature of the [Laravel architecture](https://github.com/laravel/framework/blob/9.x/src/Illuminate/Foundation/Http/Kernel.php#L108-L116). The package makes corrections during the loading of the framework and it stores its state internally, and in case of an error, it takes the value of the request from the outside. Therefore, the error text is returned in html format.

To fix this problem, you need to explicitly pass the `Accept: application/json` header in requests, or use the [`dragon-code/api-response`](https://github.com/TheDragonCode/api-response#best-practice-use-with-the-laravel-and-lumen-frameworks) package.
This package will automatically register the `DragonCode\LaravelJsonResponse\Middlewares\SetHeaderMiddleware` middleware in the `web` and `api` groups, if they exist. The
middleware will add a header `Accept` that will effectively convert all responses to JSON format. This header will apply to all responses.


[badge_build]: https://img.shields.io/github/workflow/status/TheDragonCode/laravel-json-response/phpunit?style=flat-square
Expand Down

0 comments on commit b79852d

Please sign in to comment.