Macbhee
Macbhee

Reputation: 11

including external js files in laravel 5.1.2

I'm working with laravel for the first time, i'm currently running the 5.1.2 version, i'm having issues with including external js files from the /public/js/ directory into the master view file using the asset() function. it works with css files though. i have this in my master file:

    <!-- load angularJS lib -->
<script src="{{ asset('js/angular/angular.min.js') }}" type="text/javascript"></script>
<!-- load angularJS loader lib -->
<script src="{{asset('js/angular/angular-loader.min.js')}}" type="text/javascript"></script>
<script src="{{asset('js/metro.js')}}" type="text/javascript"></script>
<script src="{{asset('js/app.style.js')}}" type="text/javascript"></script>
<script src="{{asset('js/Jquery/jquery-2.1.4.js')}}" type="text/javascript"></script>

Page renders HTML source code as such:

<!-- load angularJS lib -->
<script src="http://localhost/Online-Phone/public/js/angular/angular.min.js" type="text/javascript"></script>
<!-- load angularJS loader lib -->
<script src="http://localhost/Online-Phone/public/js/angular/angular-loader.min.js" type="text/javascript"></script>
<script src="http://localhost/Online-Phone/public/js/metro.js" type="text/javascript"></script>
<script src="http://localhost/Online-Phone/public/js/app.style.js" type="text/javascript"></script>
<script src="http://localhost/Online-Phone/public/js/Jquery/jquery-2.1.4.js" type="text/javascript"></script>

Upvotes: 1

Views: 2103

Answers (3)

Shaggy
Shaggy

Reputation: 39

Including files located in "public/" folder.

1) "URL::asset()" works only with ".blade.php" file.

<script type="text/javascript" src="{{ URL::asset('js/jquery-ui.js') }}"></script> <link rel="stylesheet" href="{{ URL::asset('css/jquery-ui.css') }}">

2) Plain file

<script type="text/javascript" src="/js/jquery-3.3.1.min.js"></script>

Upvotes: 1

AkshayBandivadekar
AkshayBandivadekar

Reputation: 840

Try this, It works

<script type="text/javascript" src="{{URL::asset('js/angular/angular.min.js')}}"></script>

Upvotes: 0

Winfred Adrah
Winfred Adrah

Reputation: 29

Try this.

{{HTML::style('css/style.css')}}

{{ HTML::script('js/javascript.js') }}

Upvotes: 0

Related Questions