2

I am using laravel 5.2 and I have problem with the assets url , I do not manage to call css to or js links

<script src="{{ URL::asset('/js/jquery.min.js') }}"></script>

or

<script src="{{ asset('/js/jquery.min.js') }}"></script>

the url in html is: http://localhost/site/js/...js.

I have tried to add public but still not working

got

NotFoundHttpException in RouteCollection.php line 161:
5
  • remove the first slash on the dir.. Commented Jun 24, 2017 at 21:06
  • Still not working thanks Commented Jun 24, 2017 at 21:11
  • What you are getting is a 404 error, I don't think it's css or js not loading. Commented Jun 24, 2017 at 21:18
  • Check you have those files in Poublic/js & Public/css Commented Jun 24, 2017 at 22:34
  • Can you check if you got the files inside of public/js and public/css? Commented Jun 24, 2017 at 23:39

6 Answers 6

2

honestly, just try it like this,

<link href="/css/app.css" rel="stylesheet">

The / at the start of the address will asume you are at starting from the root of your server, which is the public directory.

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

Comments

2

Change /vendor/laravel/framework/src/Illuminate/Foundation/helpers.php/asset() function as follows:

function asset($path, $secure = null)
{
   return app('url')->asset("public/".$path, $secure);
}

Comments

0

Change <script src="{{ URL::asset('/js/jquery.min.js') }}"></script>

to

<script src="{{ URL::asset('js/jquery.min.js') }}"></script>

Notice the / before js, possibly the reason why your css and js links are not working. Do same on the css as well.

1 Comment

Do you actually have jquery.min.js inside public/js directory?
0

Do:

  1. php artisan config: clear
  2. php artisan cache: clear
  3. delete public/css and public/js
  4. gulp
  5. try it again

you have to put your css, js, images etc in the public folder. The root of the asset method is the public folder so if you have a public/css/style.css file, you can get its path by using asset('css/style.css').

The asset folder is for storing less or sass files which have to be compiled into a css file.

1 Comment

The problem could be on your htaccess or permissions. Try to temporarily remove htaccess and try to access directly the css file. If the problem persists then you should try to chmod public/css folder and the files in to 777 and try again. Check again the path to the css file and its name. @user450_user
0

This is duplicate question. you can find my answer here also:

Why I can't obtain the complete path of a CSS resource in a blade template?

Do you see default laravel js and css files in resources folder? put your files there. I found this place the most convenient one.

You can load them in your blade like this: <link href="{!! asset('css/app.css') !!}" rel="stylesheet" type="text/css" >

if you are still facing problem try to run this on you project folder first and then try:

php artisan serve

I hope it work for you. Any question just let me know.

1 Comment

If you feel like it is a duplicate question, you should flag it as a duplicate.
0

Changing the Node version from 15.* to 12.13.0 helped me to install node modules & then I did gulp & now everything works smooth!! yeah!!

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.