Weave Code
Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Pnotify Laravel Package

alex198710/pnotify

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup in Laravel

  1. Installation:

    composer require alex198710/pnotify
    

    Publish assets (if using Laravel Mix/Vite):

    php artisan vendor:publish --tag=pnotify-assets
    

    Add to resources/js/app.js (or equivalent):

    import 'vendor/alex198710/pnotify/assets/js/pnotify.custom.min.js';
    import 'vendor/alex198710/pnotify/assets/css/pnotify.custom.min.css';
    
  2. First Use Case: Trigger a notification in a Blade view:

    <script>
    $(function() {
        new PNotify({
            title: 'Success!',
            text: 'Your action was completed.',
            type: 'success'
        });
    });
    </script>
    
  3. Where to Look First:

    • vendor/alex198710/pnotify/assets/ for raw files.
    • PNotify Docs for configuration options.

Implementation Patterns

Common Workflows

  1. Reusable Notification Service: Create a helper class in app/Services/NotificationService.php:

    class NotificationService {
        public static function success($title, $text) {
            return "<script>new PNotify({ title: '{$title}', text: '{$text}', type: 'success' });</script>";
        }
    }
    

    Usage in Blade:

    {!! NotificationService::success('Success', 'Data saved!') !!}
    
  2. Laravel Events + Notifications: Bind to events in EventServiceProvider:

    public function boot() {
        OrderCreated::listen(function ($order) {
            return "<script>new PNotify({ title: 'Order Created', text: '#{$order->id}' });</script>";
        });
    }
    
  3. Dynamic Notifications with Blade:

    @if(session('success'))
        <script>
        new PNotify({
            title: 'Success',
            text: '{{ session('success') }}',
            type: 'success'
        });
        </script>
    @endif
    
  4. AJAX Responses: Return notifications in API responses:

    $.ajax({
        url: '/update',
        success: function(response) {
            if (response.notification) {
                new PNotify(response.notification);
            }
        }
    });
    

Gotchas and Tips

Pitfalls

  1. Asset Loading:

    • If using Laravel Mix/Vite, ensure the CSS/JS are included before PNotify is initialized.
    • Avoid duplicate script tags (e.g., if publishing assets and manually including them).
  2. jQuery Dependency: PNotify requires jQuery. If using Laravel Mix, ensure jQuery is loaded first:

    import 'jquery';
    import 'pnotify.custom.min.js';
    
  3. Z-Index Conflicts: PNotify notifications may appear behind modals. Override styles:

    .pnotify {
        z-index: 9999 !important;
    }
    
  4. Symfony Legacy Config: The package’s Config.yml is for Symfony. For Laravel, use Laravel Mix/Vite or manual asset publishing.

Debugging

  • Console Errors: Check for PNotify is not defined → Verify jQuery and PNotify JS are loaded.
  • Styling Issues: Inspect the rendered HTML to ensure CSS paths are correct.

Extension Points

  1. Custom Themes: Override the default CSS in resources/css/app.css:

    .pnotify {
        background: #2d3748;
        color: white;
    }
    
  2. Laravel Facade: Create a facade for cleaner usage:

    // app/Facades/PNotify.php
    class PNotify extends \Illuminate\Support\Facades\Facade {
        protected static function getFacadeAccessor() { return 'pnotify'; }
    }
    

    Bind in AppServiceProvider:

    public function boot() {
        $this->app->singleton('pnotify', function() {
            return new NotificationService();
        });
    }
    
  3. Queue Notifications: Store notifications in the session and render them after page load:

    session(['notification' => ['type' => 'success', 'text' => 'Processed!']]);
    

    Blade:

    @if(session('notification'))
        <script>
        $(document).ready(function() {
            new PNotify({{ json_encode(session('notification')) }});
        });
        </script>
    @endif
    
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
gmostafa/php-graphql-client
xeviant/paystack
snowsoft/faker
meditationsteps/blogetc
animalyoung/laravel-influxdb
onix-solutions/sms-telera
lonely-lights/prosetta
oxygen/data
oxygen/core
jengo/base
xiloryx/log-collector
a21ns1g4ts/filament-stripe
la-php/laravel-admin
artisan-build/community-prompts
vleroy/smart
ayles-software/laravel-australian-public-holidays
cboxdk/laravel-id-spatie
cboxdk/laravel-id-billing
cboxdk/laravel-id-billing-bridge
simple-as-fuck/php-performance-log