Reputation: 53
First off, I have to precise that I'm quite new to Laravel and that I have a lot to learn.
In one of my controller I need to call a Javascript function. To do so, I simply
echo "<script>triggerPixel();</script>";
I'm just unsure about where to store my Javascript file containing that function.
From what I got for the moment is that I should use elixir to add a file with something like this in the gulpfile.js :
mix.scripts('myscript.js');
Is this the right way to do it or should I simply add a file in resources/assets/javascripts ? I'm a bit lost and some explanation would be welcome.
Thanks !
Upvotes: 1
Views: 2764
Reputation: 457
Put your actual .js file inside public/js folder
and then, put all your js reference in one file, for example footer.blade.php inside the resources/views folder.
Inside footer.blade.php :
<script src="{{ URL::asset('js/jquery-3.2.1.min.js') }}"></script>
<script type="text/javascript" src="{{ URL::asset('js/custom.js') }}"></script>
<script type="text/javascript" src="{{ URL::asset('js/app.js') }}"></script>
and then just call the footer inside one of your blade view using: @include ('footer')
Upvotes: 2