Shankar Thiyagaraajan Shankar Thiyagaraajan -4 years ago 293
PHP Question

In Laravel Blade, Script @include works, but why @push not working?

I use Laravel 5.3,
I use laravel's default template(blade) to make layout and process my page.
Here i can't use @push to include my script,
but i can use @include to work fine.

What's the issue on these two implementations ?

Why its not support @push, but same script work fine with @include

My Code :

@section('scripts')
// My Scripts //
@show


While accessing,

@push('scripts')
// My New Scripts //
@endpush


This won't work for me.

But, if i try @include,

@include('partials.scripts')


It's works perfectly !

what's wrong with this ?

Any solution for this ?

Thank you !

Answer Source

@include is just for importing/including a particular blade file.

To render any code you've pushed to a stack you need to use the @stack() directive:

@push('scripts')
    // My New Scripts //
@endpush

Then

@stack('scripts')

Hope this helps!

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download