AdRock
170
3
Laravel

@push and @stack don't seem to load javascript

Posted 3 months ago by AdRock

I have come back to using Laravel after a long break and am now using 5.8

I have created my template and included views etc but I've got a problem loading jQuery plugins.

I've tested to make sure jQuery is loaded and it is but any plugins I load using @push don't appear to load although I can see them in the source and console.

They must be loading as the reports.js file is kicking up a stink about

Uncaught TypeError: $(...).SumoSelect is not a function

When I run a test to see if any of the plugins are loaded, the console says none of them are.

This is my main template

<!DOCTYPE html>
<html lang="{{ str_replace('_', '-', app()->getLocale()) }}">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">

    <!-- CSRF Token -->
    <meta name="csrf-token" content="{{ csrf_token() }}">

    <title>{{ config('app.name', 'Laravel') }}</title>

    <!-- Scripts -->
    <script src="{{ asset('js/app.js') }}" defer></script>

    <!-- Fonts -->
    <link rel="dns-prefetch" href="//fonts.gstatic.com">
    <link href="https://fonts.googleapis.com/css?family=Nunito" rel="stylesheet" type="text/css">

    <!-- Styles -->
    <link href="{{ asset('css/app.css') }}" rel="stylesheet">
    <!-- push target to head -->
    @stack('styles')
</head>
<body>
    <div id="app">
        
    </div>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.0/jquery.min.js"></script>
    <!-- or push target to footer -->
    @stack('scripts')
</body>
</html>

This is my view which causes the problem

@extends('layouts.main')

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

@push('styles')
<link href="{{ asset('libraries/sumoselect/css/sumoselect.css') }}" rel="stylesheet" media="screen">
<link href="{{ asset('libraries/flatpickr/css/flatpickr.min.css') }}" rel="stylesheet" media="screen">
@endpush

@push('scripts')
<script src="{{ asset('libraries/sumoselect/js/jquery.sumoselect.min.js') }}"></script>
<script src="{{ asset('libraries/chartjs/js/Chart.min.js') }}"></script>
<script src="{{ asset('libraries/flatpickr/js/flatpickr.js') }}"></script>

<script src="{{ asset('js/reports/reports.js') }}"></script>
@endpush

and finally this is my reports.js

$('#report-types, #base-chart-types').SumoSelect({ 
        okCancelInMulti: true ,
        triggerChangeCombined: false,
        isClickAwayOk: true,
        selectAll: true,
        forceCustomRendering: true
    });

Please sign in or create an account to participate in this conversation.