Why not simply say
return response()->json([ 'error': 404, 'message': 'Not found' ]);
@astroanu : It is not really a solution because it is not a HTTP error. The answer status will be 200 and not 404 here. And I would like that the answer will be 404 and not 200.
You can pass the http code on to the json method as follows:
return response()->json([ 'error': 404, 'message': 'Not found' ], 404);
From the Laravel documentation
json(string|array $data = array(), int $status = 200, array $headers = array(), int $options)
Actually i misread your first post. On L5 you can simply do this on your controller.
abort(404, 'Doomed');
Thank you very much this worked for me...
astroanu said:
You can pass the http code on to the json method as follows:
return response()->json([ 'error': 404, 'message': 'Not found' ], 404);
From the Laravel documentation
json(string|array $data = array(), int $status = 200, array $headers = array(), int $options)
astroanu said:
You can pass the http code on to the json method as follows:
return response()->json([ 'error': 404, 'message': 'Not found' ], 404);
From the Laravel documentation
json(string|array $data = array(), int $status = 200, array $headers = array(), int $options)
I think you meant to put hash rockets :)
return response()->json([ 'error' => 404, 'message' => 'Not found' ], 404);
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community