PHP code example of belysh / laravel-socket-bridge
1. Go to this page and download the library: Download belysh/laravel-socket-bridge 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/ */
belysh / laravel-socket-bridge example snippets
namespace App\Events;
use Illuminate\Broadcasting\InteractsWithSockets;
use Illuminate\Broadcasting\PrivateChannel;
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
class OrderUpdated implements ShouldBroadcast
{
use InteractsWithSockets;
public function __construct(public int $orderId, public string $status) {}
public function broadcastOn(): array
{
return [new PrivateChannel('orders.'.$this->orderId)];
}
public function broadcastAs(): string
{
return 'order.updated';
}
}
use Illuminate\Support\Facades\Broadcast;
Broadcast::channel('orders.{orderId}', function ($user, int $orderId) {
return $user->orders()->whereKey($orderId)->exists();
});