4

I just want an alert to work and then I will go on my own, but when I write alert() in my recources/js/app.js it doesn't work, but my scss works, I ran npm run watch doesn't help, what to do, and why I can't find any information on google on just how to use js on laravel? :/

my mix file mix

my js file js

5
  • Are you including the JS file from the public folder in your blade file? Commented Mar 14, 2021 at 3:52
  • hmm, no isn't it being automatically? because my scss is compiling and sending to public/css/app.css automatically, I am very new to Laravel Yes that was the case, please answer it I will accept it :) Commented Mar 14, 2021 at 3:55
  • Mix is just compiling the files, they aren't automatically injected into your blade files. Just take a look at your blade file, you should see something like <script src="{{ asset('js/app.js') }}"></script> and <link href="{{ asset('css/app.css') }}" rel="stylesheet"> Commented Mar 14, 2021 at 3:59
  • 1
    Oh, I forgot that I've deleted the dafault welcome.blade.php and created a new blank one lol, thanks for the answer, just post it I will accept and upvote it :D Commented Mar 14, 2021 at 4:05
  • I don't think the welcome blade includes them anyway. Commented Mar 14, 2021 at 4:08

2 Answers 2

1

Mix is just compiling the files, they aren't automatically injected into your blade files. Just take a look at your blade file, you should see something like

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

and

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

Comments

1

you should add this code in your app.blade.php

<link href="{{ asset('css/app.css') }}" rel="stylesheet">
<script src="{{ asset('js/app.js') }}"></script> 

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.