How to use js in Laravel

Viewed 281

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

2 Answers

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">

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> 
Related