How to add a script tag inside a Laravel Blade template
Sometimes you may need to add a little bit of javascript inside a Laravel Blade template. The proper way to do that is to use Laravel's `@stack` directive:
First, you need to add a `@stack` on the parent page or the layout:
```html
<script src="{{ asset('js/app.js') }}"></script>
@stack('other-scripts')
```
Then you need to `@push` the respective script on the page you need it on.
```html
@push('other-scripts')
<script>
console.log('do something in js')
</script>
@endpush
```
Zeno Popovici
05 Jan 2022
« Back to post