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

anjanesh's avatar

Server-Sent Event Notification

I understand there is a 3rd party service called pusher.

I want to know if there is some vendor package with an admin UI where I just want to send an alert notification message to all or a select range of users by an admin kind user.

Is there some composer package for getting this done ?

0 likes
3 replies
LaryAI's avatar
Level 58

To implement server-sent event notifications with an admin UI using a package, you can consider using Laravel Echo with Pusher or Laravel WebSockets. However, if you're looking for a package that provides an admin UI for sending notifications, you might need to combine a few tools or build a custom solution.

Here's a general approach using Laravel and Pusher:

  1. Install Laravel Echo and Pusher:

    First, ensure you have Laravel installed. Then, install Laravel Echo and Pusher:

    composer require pusher/pusher-php-server
    npm install --save laravel-echo pusher-js
    
  2. Configure Pusher:

    Set up your Pusher credentials in your .env file:

    PUSHER_APP_ID=your-app-id
    PUSHER_APP_KEY=your-app-key
    PUSHER_APP_SECRET=your-app-secret
    PUSHER_APP_CLUSTER=your-app-cluster
    

    Update your config/broadcasting.php to use Pusher:

    'connections' => [
        'pusher' => [
            'driver' => 'pusher',
            'key' => env('PUSHER_APP_KEY'),
            'secret' => env('PUSHER_APP_SECRET'),
            'app_id' => env('PUSHER_APP_ID'),
            'options' => [
                'cluster' => env('PUSHER_APP_CLUSTER'),
                'useTLS' => true,
            ],
        ],
    ],
    
  3. Create a Notification:

    Use Laravel's notification system to create a notification:

    php artisan make:notification AlertNotification
    

    In AlertNotification.php, define the notification:

    public function via($notifiable)
    {
        return ['broadcast', 'database'];
    }
    
    public function toBroadcast($notifiable)
    {
        return new BroadcastMessage([
            'message' => 'This is an alert notification!',
        ]);
    }
    
  4. Broadcast the Notification:

    You can broadcast the notification to all users or a specific group:

    Notification::send(User::all(), new AlertNotification());
    
  5. Admin UI:

    For the admin UI, you can create a simple form in your Laravel application where an admin can input the message and select users or groups to notify. Upon submission, trigger the notification logic.

  6. Frontend Setup:

    Use Laravel Echo to listen for the notifications on the client side:

    import Echo from "laravel-echo";
    window.Pusher = require('pusher-js');
    
    window.Echo = new Echo({
        broadcaster: 'pusher',
        key: process.env.MIX_PUSHER_APP_KEY,
        cluster: process.env.MIX_PUSHER_APP_CLUSTER,
        forceTLS: true
    });
    
    Echo.channel('notifications')
        .listen('AlertNotification', (e) => {
            console.log(e.message);
        });
    

This setup will allow you to send notifications from an admin interface to users using Laravel's built-in notification system and Pusher for real-time updates. If you need a more comprehensive admin UI, you might need to build it or look for third-party solutions that integrate with Laravel.

Please or to participate in this conversation.