PHP code example of sockudo / laravel

1. Go to this page and download the library: Download sockudo/laravel library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

sockudo / laravel example snippets


use Illuminate\Broadcasting\PrivateChannel;
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;

final class OrderUpdated implements ShouldBroadcast
{
    public function __construct(public readonly string $orderId)
    {
    }

    public function broadcastOn(): PrivateChannel
    {
        return new PrivateChannel("orders.{$this->orderId}");
    }
}

use Illuminate\Support\Facades\Broadcast;

Broadcast::channel('orders.{order}', function ($user, $order) {
    return $user->can('view', $order);
});

use Sockudo\Laravel\Facades\Sockudo;

$page = Sockudo::getChannelHistory('orders', ['limit' => 50]);

Sockudo::updateMessage('orders', $messageSerial, [
    'data' => ['status' => 'paid'],
]);

Sockudo::publishAnnotation('orders', $messageSerial, [
    'type' => 'reaction',
    'name' => 'confirmed',
]);

$publish = Sockudo::publishPush([
    'recipients' => [['type' => 'channel', 'channel' => 'orders']],
    'payload' => ['title' => 'Order updated'],
    'publishId' => 'order-updated:ord-123:v4',
]);

use Sockudo\SockudoInterface;

final class LoadOrderHistory
{
    public function __construct(private SockudoInterface $sockudo)
    {
    }
}

$client = Sockudo::connection('sockudo-eu');
bash
php artisan sockudo:check