I am trying to create my first Laravel site, but I can't figure out how to add a JS file to one of my pages.
I only want the JS file to be used on this page and no where else.
How do I get my page to load the JS file?
My directory structure is like so:
apply
js
myjsfile.js
apply.blade.php
In my apply.blade.php
@extends('layouts.master')
@section('content')
<div class="row">
<div id="applicationForm" class="col-md-9 col-xs-12">
...
</div>
</div>
layouts.master file
<!DOCTYPE html>
<html>
<head>
@include('includes.head')
</head>
<body>
<div class="container">
<div id="header">
@include('includes.header')
</div>
@yield('content')
<div id="footer">
@include('includes.footer')
</div>
</div>
</body>
</html>
your apply.blade.php
@extends('layouts.master')
@section('content')
<div class="row">
<div id="applicationForm" class="col-md-9 col-xs-12">
...
</div>
</div>
@stop
@section('myjsfile')
<script src="js/myjsfile.js"><script>
@stop
your layouts.master
<!DOCTYPE html>
<html>
<head>
@include('includes.head')
</head>
<body>
<div class="container">
<div id="header">
@include('includes.header')
</div>
@yield('content')
<div id="footer">
@include('includes.footer')
</div>
</div>
@yield('myjsfile')
</body>
</html>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With