John Davidson

php - Forcing json responses for API not working on laravel 8

0 comments
Message:


I'm building an small API with passport auth with laravel 8 and also using FormRequest classes for validations requests.


Problem is that when an error occurrs, API doesn't respond with JSON, it just returns nothing.


I've already created a new Middleware to handle only json responses by adding this $request->headers->set('Accept', 'application/json');on the handle method, but it doesn't seem to be working!


Does anyone knows if I'm missing something?



My Answer:
>headers->set('Accept', 'application/json');

But it's still not working. How can I force JSON responses for my API in Laravel 8?

Rate this post

5 of 5 based on 3284 votes

Comments




© 2024 Hayatsk.info - Personal Blogs Platform. All Rights Reserved.
Create blog  |  Privacy Policy  |  Terms & Conditions  |  Contact Us