0

I tried searching for solutions on how to return json response in laravel but after trying few variations i was lost on this matter, an explanations would be nice:

why is it that whenever i add a status codes in the json() function like this

response()->json(['hello'=> $someErrors], 401)

I dont get the $someErrors data in the console log of my js code but when i remove it and do it like

response()->json($someErrors);

or

response($someErrors);

i get my $someErrors data in the console log of my js code.

Thanks in advance!

1 Answers1

0

I think you're not generating valid renounce to catch in your view. Try to through json exception:

$api_errors = $validator->errors();
throw new HttpResponseException(
    response()
    ->json($result, $api_errors)
    ->withHeaders(['Content-Type' => 'text/plain', 'charset' => 'utf-8'])
);
meph
  • 209
  • 1
  • 5
  • 16