PHP Vars to JavaScript Laravel 5.2 -
i using this package pass variables javascript in laravel 5.2, get:
all.js:56uncaught referenceerror: categories not defined
in controller trying pass variables this:
javascript::put([ 'categories' => $numberofviewsbycategory[0], 'categoryviews' => $numberofviewsbycategory[1], 'chains' => $numberofviewsbychain[0], 'chainviews' => $numberofviewsbychain[1] ]);
i have set path in config file:
'bind_js_vars_to_this_view' => 'layouts.partials.foot',
and partials.foot blade looks this:
@section('foot') <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.2.3/jquery.min.js" integrity="sha384-i6f5okeclvtk/bl+8isldehowsafuo76zl9+kgagtrdibyinkjaqtph/qvns1vdb" crossorigin="anonymous"></script> <script type="text/javascript" src="{{ asset('js/zurb/zurb.js') }}"></script> <script type="text/javascript" src="{{ asset('js/jquery-ui/jquery-ui.min.js') }}"></script> <script src="//cdn.tinymce.com/4/tinymce.min.js"></script> <script type="text/javascript" src="{{ asset('js/jquery-filer/jquery-filer.js') }}"></script> <script type="text/javascript" src="{{ asset('js/editor/editor.js') }}"></script> <script src="https://code.highcharts.com/highcharts.js"></script> <script src="https://code.highcharts.com/modules/exporting.js"> </script> <script src="{{ asset('js/all.js') }}"></script> @stop
but when console.log(categories) in all.js file, above mentioned error.
the documentation says:
which view want new javascript variables to prepended to.
so suppose in layout.blade.php
have @yield('footer')
moment.
i suggest editing foot.blade.php
like:
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.2.3/jquery.min.js" integrity="sha384-i6f5okeclvtk/bl+8isldehowsafuo76zl9+kgagtrdibyinkjaqtph/qvns1vdb" crossorigin="anonymous"></script> <script type="text/javascript" src="{{ asset('js/zurb/zurb.js') }}"></script> <script type="text/javascript" src="{{ asset('js/jquery-ui/jquery-ui.min.js') }}"></script> <script src="//cdn.tinymce.com/4/tinymce.min.js"></script> <script type="text/javascript" src="{{ asset('js/jquery-filer/jquery-filer.js') }}"></script> <script type="text/javascript" src="{{ asset('js/editor/editor.js') }}"></script> <script src="https://code.highcharts.com/highcharts.js"></script> <script src="https://code.highcharts.com/modules/exporting.js"> </script> <script src="{{ asset('js/all.js') }}"></script>
and in layout, replace @yield
@include('partials.foot')
Comments
Post a Comment