Skip to content

Update README.md #13

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 11, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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