12

This is my directory structure.

-resources
  -css
    -mycss.css
  -js
    -myjs.js
  -myimagesfolder
  -views
    -admin
      -home.blade.php

how can i access resources>css>mycss.css , resources>js>myjs.js and resources>mymagesfolder>images in my views>admin>home.blade.php.

2
  • You need to store your publicly available files and folders under the public folder and then you can use the asset() helper method to generate. E.g. in your blade file use, <img src="{{ asset('images/logo.png') }} /> Commented Sep 20, 2020 at 5:58
  • @OMiShah and css and Js? Commented Sep 20, 2020 at 6:02

4 Answers 4

34

Put your css and js file inside public folder like this:

-public
  -css
    -mycss.css
  -js
    -myjs.js

Now you can access your files like this.Putthis below line of code inside head tag

For css

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

For Js

<script src="{{asset('js/myjs.js')}}"></script>
Sign up to request clarification or add additional context in comments.

Comments

12

According to Laravel official documents link, files under /resources/css, /resources/js need be compiled before use.

1 Comment

compiled as in... doing what exactly? npm install / npm run dev ?
6

You can compile files in resources/css resources/js with Laravel mix.

For myjs.js, add to webpack.mix.js file the line: mix.js('resources/js/myjs.js', 'public/js'); For mjcss.css, add to webpack.mix.js file the line: mix.postCss('resources/mycss.css', 'public/css');

Both myjs.js and mycss.css will be compiled to public/js and public/css respectively when you run npm run dev

Remember to include the minified js and css files in your app.blade.php

<script src="{{ asset('js/myjs.js') }}" defer></script>

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

Comments

1

Please move all your public files to the public folder:

-public
  -css
    -mycss.css
  -js
    -myjs.js
-resources
  -myimagesfolder
  -views
    -admin
      -home.blade.php

then import them as follow:

<link rel="stylesheet" href="{{asset('css/mycss.css')}}"> ## CSS
<script src="{{asset('js/myjs.js')}}"></script> ## JS

Best of luck!

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.