Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CSS and JS not working over HTTPS in laravel

My CSS and JS file work fine on localhost but when up to host it not working. I use laravel 5.4. I tried a lot of ways but still failed. enter image description here

My embedded CSS and JS code enter image description here

UPDATE: Thanks all i have fixed my problems follow this:
1. change http://localhost to https://localhost at APP_URL line in .env file
2. add \URL::forceScheme('https') to AppServiceProvider.php file in boot() function
3. the last is include {{asset('--link_on_href--')}} for each CSS and JS embeded on index.php

like image 294
Trương Việt Avatar asked Jul 24 '26 02:07

Trương Việt


1 Answers

Use the asset() helper to include assets in your view. This will automatically generate the appropriate URL for the included files based on you APP_URL in your .env file.

For CSS,

<link href="{{ asset('css/app.css') }}" rel="stylesheet" type="text/css" >

Or

<link href="{{ URL::asset('css/app.css') }}" rel="stylesheet" type="text/css" >

For JS,

<script type="text/javascript" src="{{ asset('js/custom.js') }}"></script>

Or

 <script type="text/javascript" src="{{ URL::asset('js/custom.js') }}"></script>

For Images and other such assets,

{{ asset('img/photo.jpg'); }}

Link to the Docs

like image 167
Sapnesh Naik Avatar answered Jul 26 '26 06:07

Sapnesh Naik



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!