Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

jcgivens21's avatar

Toastr Notifications Not Working After Other Package Is Installed

I added Spatie's Google Tag Manager to my application (https://github.com/spatie/laravel-googletagmanager)

Ever since adding it, my Toastr notifications have stopped working, and I have no idea why. The Toastr package I'm using is this one (https://packagist.org/packages/oriceon/toastr-5-laravel)

There are 3 items that get included in your template (the .css, the .js, and then a little render() function call).

The .css and .js are loading just fine; however, the {!! Toastr::render() !!}} function is not getting called on the page. When I use chrome dev tools to look at the elements of the page, it should print out the Toastr options, but it's not including them.

Any thoughts? I've tried removing the spatie package, but it still has not resolved the conflict.

I've also run composer dump-autoload, all variables of php artisan clear, and even manually deleted the cache files in bootstrap/cache. None have seemed to have any effect.

I should also mention that there are no errors in the log. So I can't track down why it isn't loading. I've also checked storage/logs to see if there's any detail in there, and I can't find anything related to toastr there either.

0 likes
7 replies
bobbybouwmann's avatar

So if removing the spatie package doesn't make this work, the problem is not in the package right?

Can you show some of the output and your view template? Maybe we can spot a difference?

jcgivens21's avatar

Hello @bobbybouwmann. Thanks for the response. Here is my view template that I use for basically every page:

<!DOCTYPE html>
<html>
    <head>
        <link rel="icon" href="{{ url('favicon.ico') }}" type="image/x-icon" />

        <style>
            hr.gradientStyle 
            { 
                border: 0; 
                height: 1px; 
                background-image: -webkit-linear-gradient(left, #f0f0f0, #8c8b8b, #f0f0f0);
                background-image: -moz-linear-gradient(left, #f0f0f0, #8c8b8b, #f0f0f0);
                background-image: -ms-linear-gradient(left, #f0f0f0, #8c8b8b, #f0f0f0);
                background-image: -o-linear-gradient(left, #f0f0f0, #8c8b8b, #f0f0f0); 
            }
        </style>


        {{-- Google Tag Manager Head --}}
        {{-- @include('googletagmanager::head') --}}
        
        @include('layouts/admin_common/head')
        @yield('page-style-files')
        @yield('page-style-custom')

    </head>


    <body class="skin-blue sidebar-collapsed">
        <div class="wrapper">
            

            {{-- Google Tag Manager Body --}}
            {{--@include('googletagmanager::body')--}}

            {{-- Header --}}
            @include('layouts/admin_common/header')

            {{-- Sidebar --}}
            @include('layouts/admin_common/sidebar')

            {{-- Content Wrapper. Contains page content --}}
            <div class="content-wrapper">
                <section class="content-header">
                    <h3 align="center">{{ $page_title ?? "Page Title" }}</h3>
                    <hr class="gradientStyle">
                </section>

                <section class="content">
                    <div id="root">
                        @yield('content')
                    </div>
                </section>
            </div>


            @include('layouts/admin_common/footer')

        </div>{{-- ./wrapper --}}

        @include('layouts/admin_common/script_includes')
        @yield('page-js-files')
        @yield('page-js-script')

        {{-- Toastr Notification Popups --}}
        {!! Toastr::render() !!}
        
    </body>
</html>

I have 3 environments. Local, Staging, and Production. Local the package has been installed. Staging the package has been installed. Production the package did not get installed/pushed. The only difference in the template page between the 3 is the lack of the @include('googletagmanager') calls.

On production, if I use chrome dev tools, I see the rendered Toastr script that gets included by {!! Toastr::render() !!}}:

<script type="text/javascript">toastr.options = {"closeButton":true,"debug":false,"newestOnTop":true,"progressBar":true,"positionClass":"toast-bottom-right","preventDuplicates":false,"onclick":null,"showDuration":"300","hideDuration":"1000","timeOut":"5000","extendedTimeOut":"1000","showEasing":"swing","hideEasing":"linear","showMethod":"fadeIn","hideMethod":"fadeOut"};toastr.success('Employee has been updated.', 'Success!');</script>

On Local and Staging, the script above does not get generated.

I get your point that it shouldn't be the package; however, Toastr worked fine before the tag manager package and now it doesn't. Upon removing, it doesn't seem to have any effect. I've deleted the tag manager reference in composer.json, cleaned up the references in \config\app.config, cleaned up the service reference in app\Http\Kernal.php, ran composer update, composer dump-autoload, all the php artisan clears, deleted the cache files in boostrap\cache\ ...I'm just at a loss on what's happening or how to troubleshoot why the Toastr::render() is not getting called.

jcgivens21's avatar

Spinning up a test project now to see if I get the same results.

jcgivens21's avatar

So I tested it in a brand new, blank project. Toastr works fine before google tag manager install. Toastr breaks after tag manager package install. Though in my "fresh" app, upon removal of the tag manager package, Toastr works again. The primary project is still broken. So I'll have to look into what's up...

jcgivens21's avatar

My guess is that when I run:

php artisan vendor:publish --provider="Spatie\GoogleTagManager\GoogleTagManagerServiceProvider" --tag="config"

This causes something to break in the Toastr package. Not sure how to track down what's broken though. May try removing Toastr and re-adding it.

bobbybouwmann's avatar

I don't see anything strange. Maybe a certain config of class is overridden in the container?

I'm not sure if I can help you with this.

jcgivens21's avatar
jcgivens21
OP
Best Answer
Level 3

So through a series of troubleshooting with the "fresh test app", I've determined the exact point in the Spatie installation process that breaks the Toastr notifications. When you add this to the Kernel.php:

// app/Http/Kernel.php

protected $middleware = [
    ...
    \Illuminate\Session\Middleware\StartSession::class,
    \Spatie\GoogleTagManager\GoogleTagManagerMiddleware::class,
    ...
];

That's what breaks the Toastr notifications. Not the vendor publish. In my fresh test app, I can comment these lines out, and everything works great.

Specifically the culprit is the StartSession middleware. If I comment out the TagManager line, but leave the StartSession line in there, Toastr is broken; however, if I comment out the Startsession and leave the TagManager running, Toastr works.

So I'm not sure I care to troubleshoot any further, but I'll leave this discussion here for anyone else in the future who gets baffled by this.

The final summary to all of this is to not use the: "\Illuminate\Session\Middleware\StartSession::class," middleware in Spatie Google Tag Manager if you are currently using Oriceon's Toastr notifications package.

Please or to participate in this conversation.