To address the issue of Laravel Octane serving assets over non-secure URLs, which can lead to CORS errors, you need to ensure that Octane is aware that it should serve content over HTTPS. This is particularly important when running in a production environment where HTTPS is expected.
The solution is to set the OCTANE_HTTPS environment variable to true in your .env file. This instructs Laravel Octane to generate URLs with the https scheme, ensuring that all assets and resources are served securely.
Here's how you can do it:
-
Open your
.envfile located in the root of your Laravel project. -
Add the following line to the file:
OCTANE_HTTPS=true -
Save the changes to your
.envfile.
By setting OCTANE_HTTPS=true, you inform Laravel Octane to treat all URLs as secure, which should resolve the CORS errors related to mixed content (i.e., trying to load resources over HTTP when the page is served over HTTPS).
After making this change, restart your Octane server to ensure the new environment variable is loaded:
php artisan octane:restart
This should resolve the issue with non-secure URLs and CORS errors when using Laravel Octane in a production environment.