1. Go to this page and download the library: Download relaystacks/laravel-conduit 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/ */
class OrderShipped implements ShouldBroadcast
{
public function __construct(public Order $order) {}
public function broadcastOn(): array
{
return [new PrivateChannel('orders.' . $this->order->user_id)];
}
public function broadcastWith(): array
{
return ['order_id' => $this->order->id];
}
}
Broadcast::channel('news', function () {
return true;
});
Broadcast::channel('orders.{userId}', function (User $user, int $userId) {
return $user->id === $userId;
});
Broadcast::channel('chat.{roomId}', function (User $user, int $roomId) {
return ['id' => $user->id, 'name' => $user->name];
});
// Private — must return true/false
Broadcast::channel('orders.{userId}', function (User $user, int $userId) {
return $user->id === $userId;
});
// Presence — must return an array with user info
Broadcast::channel('chat.{roomId}', function (User $user, int $roomId) {
return ['id' => $user->id, 'name' => $user->name];
});