3

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

3
  • use asset helper like this, <link href="{{ asset('css/bootstrap.min.css') }}" rel="stylesheet"> Commented Feb 3, 2018 at 6:27
  • arun kunmar: I have tried it but still error :( Commented Feb 3, 2018 at 10:03
  • You literally saved my day man! Your solution worked like WOW. I have already done the 3rd point but starting 2 points are life-savers :) Thanks alot!!! Commented May 11, 2018 at 1:15

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.