0

Could you tell me how to link css and js file in laravel according to my file structure I wanna link app.css and app.js into museum.blade.php (inside portfolio)

I have try something like this: <link rel="stylesheet" href="{{ asset('resources/css/app.css')}}">, but it did not work

here is my file structure

enter image description here

please help me, thank you so much

2
  • 1
    i see a ">" for app.css is it because that's a folder? if yes then i think <link rel="stylesheet" href="{{ asset('resources/css/app.css/app.css')}}"> and if i am not mistaken, you are supposed to but it in the public folder not resources folder Commented Apr 9, 2022 at 13:14
  • 4
    For any CSS and JS that is under resources you need to check compiling assets. If you don't want to compile them then put them under your /public folder Commented Apr 9, 2022 at 13:16

3 Answers 3

2

I have try something like this: , but it did not work

This happens because resources folder are not to be consumed "public", the folder that would be consumed by "public" is a public folder, you need to compile them from resource to public first. Laravel has great documentation about it at Laravel Mix

To fix your problem, you need to find a file on your project directory called "webpack.mix.js"

and put this mix code on it.

mix.js('resources/js/app.js', 'public/js')
   .js('resources/js/museum.js', 'public/js')
  .sass('resources/sass/app.scss', 'public/css')

and then you can run npm run dev at your command line to compile the assets.

it will compile your targeted resources on webpack mix to public.

After that, on the head of your museum.blade.php, you can call it like

<link rel="stylesheet" href="{{ mix('css/app.css') }}">
<script src="{{ mix('js/app.js') }}" defer></script>
Sign up to request clarification or add additional context in comments.

Comments

0

If your project has Vite installed, you can put @vite(['resources/css/app.css','resources/js/app.js']) in your welcome.blade.php file.

When creating a Laravel project using Composer, for Laravel framework version 10+ (not sure if exists in previous versions), you should also find a vite.config.js in the main parent directory. Using Node.js, do npm install then Vite should automatically be installed and available to use as specified above.

Comments

0

First Step : Make a folder called css in public folder like this

Second Step : Put your css file here (like public/css/style.css)

Third Step : link it using this code in your html code

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

Enjoy !

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.