こんにちは、私は Laravel を初めて使用し、現在 Laravel 6.0 を使用しています。
何らかの理由で、@push を使用する JavaScript が機能しません。スクリプトは、コードをブレード ファイルに貼り付け、アセット フォルダーを使用しない場合にのみ機能します。
add.blade.php
@extends('layouts.app')
@section('content')
// Long HTML code
@endsection
@push('scripts')
<script src="{{ asset('js/position.js') }}"></script>
@endpush
レイアウト > app.blade.php
<main class="py-4">
@yield('content')
</main>
</div>
@stack('scripts')
</body>
public(asset) > js > position.js
$('#department').change(function(){
var departmentID = $(this).val();
if(departmentID) {
$.ajax({
type:"GET",
url:"{{url('get-section-list-position')}}?department_id="+departmentID,
success:function(res){
if(res) {
$("#section").empty();
$("#section").append('<option>Please Select Section</option>');
$.each(res,function(key, value){
$("#section").append('<option value="'+key+'">'+value+'</option>');
});
} else {
$("#section").empty();
}
}
});
} else {
$("#section").empty();
}
});
スクリプトを add.blade.php に貼り付けて @section を使用すると動作しますが、システムのセキュリティが損なわれるのではないかと心配しています。助けてください。