Support the ongoing development of Laravel.io →
Configuration Requests Views
Last updated 2 years ago.
0

Why not simply say

return response()->json([ 'error': 404, 'message': 'Not found' ]);
Last updated 9 years ago.
0

@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.

0

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)
Last updated 9 years ago.
0

Actually i misread your first post. On L5 you can simply do this on your controller.

abort(404, 'Doomed');
0

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)
0

^_^ glad it helped someone

0

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);
0

haha .. i've been coding too much js lately.

0

Sign in to participate in this thread!

Eventy

Your banner here too?

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.