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

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