Friday, 17 June 2022

Including Javascript codes with @stack not working

I'm working with Laravel 8 and I have a master.blade.php goes like this:

<!DOCTYPE html>
<html>
   <head>
      <!-- including scripts and stylesheets -->
   </head>
   <body>
      @yield('content')

      <script src="/plugins/jquery/jquery.min.js"></script>
      @stack('scripts')
   </body>
</html>

Then at content.blade.php, I added this as my dynamic content:

@extends('admin.master')

@section('content')
   
   ...
   
@endsection

After that I have created some new file and used the components like this:

@component('admin.layouts.content' , ['title' => 'example file'])
   @slot('breadcrumb')
        <li class="breadcrumb-item active">Example File</li>
   @endslot
   ...
@endcomponent

@push('scripts')
   <script>
   console.log(1); // to check if the js codes can be run on page
   </script>
@endpush

But the problem is that @push('scripts') not working at all! Meaning that this way of including Javascript codes is wrong.

So how can I properly include them in my example page properly?

Note that I don't want to include js codes in content.blade.php because it loads in every single page!



from Including Javascript codes with @stack not working

No comments:

Post a Comment