I am trying to get Laravel 5 (5.1.31) to return a http status response of 404 when a page is not found. I have tried several things and it always returns 200.
In my controller I have this:
else { header('HTTP/1.0 404 Not Found'); return view('errors.404); }
I have also tried:
else { http_response_code(404); return view('errors.404); }
and
else { abort(404, 'Page not found'); }
I also tried putting this in the 404.blade
@inject( 'response', 'Illuminate\Http\Response' ) {{ $response->status(404) }}
No success. No matter what I try, Laravel returns 200. How do I get it to return 404?
Default 404 Page: Now you have to just create "errors" folder in your resources directory and then after you need to create 404. blade. file inside that folder. So, basically laravel will stetted default design, but if you created 404 file into "errors" directory then it will take from there.
If the server does not know, or has no facility to determine, whether or not the condition is permanent, the status code 404 (Not Found) SHOULD be used instead.
you may use the abort helper:
abort(404);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With