I\'m trying to use laravel blade templates including some javascript code into child view.
I have my mail app.blade.php file, where is placed string
Please follow this way
for jquery script file do this
<script src="{!!url('/js/jquery.min.js')!!}"></script>
and do this for content section
@extends('layouts.app')
@section ('content')
Settings main page
<script type="text/javascript">
$(document).ready(function() {
alert("Settings page was loaded");
});
</script>
@endsection
Updated
Rather to scripting in content section, it would much better and professional way to create another section for scripting in app.blade.php
normally I follow this way
<html>
<head>
@yield('page-style-files')
</head>
<body>
<div class="wrapper">
@yield('content')
</div>
</body>
@yield('page-js-files')
@yield('page-js-script')
<html>
so for example your code will look like this
@extends('layouts.app')
@section ('content')
Settings main page
@endsection
@section('page-style-files')
<link href="....css" />
@stop
@section('page-js-files')
<script src=".....js"></script>
@stop
@section('page-js-script')
<script type="text/javascript">
$(document).ready(function() {
alert("Settings page was loaded");
});
</script>
@stop
I had this same problem which seemed more to do with the js files being loaded in with the defer attribute.
I was getting the same console warning about $ not being defined.
So I tested this notion with...
<script type="text/javascript">
setTimeout(function () {
$(document).ready(function(){
alert('now');
});
}, 5000);
</script>
Which then worked, so I assume it's to do with defer (using Firefox Developer Edition on Linux Mint).
Anyway, a good reason to put all my scripts into proper js files ;-)