Category: Laravel, PHP, api, javascript

Sometimes we need to fetch static resources (PDF files, images, videos etc)from a server via a HTTP client in the browser, eg. So we try this in JavaScript: But we see our good old friend CORS error :)

Well it turns out when we request static resources, the web server will serve them directly without passing the HTTP request through Laravel. Since the PHP code in Laravel doesn’t run, the CORS middleware will not run, and therefore the CORS headers are not added to the HTTP response. Before you slam your head against the wall, try to add the following to your server config.
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