Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding a JS script to a Laravel page

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>
like image 452
imperium2335 Avatar asked Dec 11 '22 03:12

imperium2335


1 Answers

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>
like image 141
worldask Avatar answered Jan 12 '23 06:01

worldask