skip to Main Content

I use Form Requests to incapsulate validation logic into files then to use it like:

   public function register(RegisterRequest $request) {}

When validation is false it redirects to the index page.

How to return json with http code instead redirection?

2

Answers


  1. From postman, you have to pass Accept as application/json on header tab

    enter image description here

    Login or Signup to reply.
  2. use following code :

    return response($data, $statusCode);
    

    for example :

    return response(['name'=>'Amin'], 200);
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search