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);
});