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

Fathom Analytics | Fast, simple and privacy-focused website analytics. Fathom Analytics | Fast, simple and privacy-focused website analytics.
Achieve superior email deliverability with ToastMail! Our AI-driven tool warms up inboxes, monitors reputation, and ensures emails reach their intended destination. Sign up today for a spam-free future. Achieve superior email deliverability with ToastMail! Our AI-driven tool warms up inboxes, monitors reputation, and ensures emails reach their intended destination. Sign up today for a spam-free future.
Community Partners