Category: Laravel, PHP, javascript

Working with Laravel’s https://laravel.com/docs/8.x/http-client, there might be the scenario where the outgoing HTTP requests that you’re making might return responses with different status codes. Among all the https://developer.mozilla.org/en-US/docs/Web/HTTP/Status, two response codes are sent when the user is not authorized to access the resources for two different reasons. https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/401 — The status code indicates that the client request has not been completed because it lacks valid authentication credentials for the requested resource. https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/403 — The status code indicates that the server understands the request but refuses to authorize it.

Now, the Laravel HTTP client lets you check these status codes through the status() method that you can call on the HTTP response like so.
Newsletter

Get the latest Laravel/PHP jobs, events and curated articles straight to your inbox, once a week

Glimpse streamlines Laravel development by seamlessly deploying GitHub pull requests to preview environments with the help of Laravel Forge. Glimpse streamlines Laravel development by seamlessly deploying GitHub pull requests to preview environments with the help of Laravel Forge.
Fathom Analytics | Fast, simple and privacy-focused website analytics. Fathom Analytics | Fast, simple and privacy-focused website analytics.
Shirts painstakingly handcrafted by under-caffeinated developers. Shirts painstakingly handcrafted by under-caffeinated developers.
Community Partners