PHP code example of behzadsh / rabbitmq-broadcaster
1. Go to this page and download the library: Download behzadsh/rabbitmq-broadcaster 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/ */
return [
// ...
'providers' => [
// Other service providers...
Behzadsh\RabbitMQBroadcaster\RabbitMQBroadcasterServiceProvider::class,
]
// ...
];
namespace App\Events;
use Illuminate\Broadcasting\Channel;
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
class UserRegistered implements ShouldBroadcast
{
/**
* Create a new event instance.
*/
public function __construct(
public int $userId,
public string $name,
public string $email,
) {}
/**
* Get the channels the event should broadcast on.
*
* @return array<int, \Illuminate\Broadcasting\Channel>
*/
public function broadcastOn(): array
{
return [
new Channel('user.events'),
];
}
}
namespace App\Events;
use Illuminate\Broadcasting\Channel;
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
use Illuminate\Queue\SerializesModels;
class ServerCreated implements ShouldBroadcast
{
use SerializesModels;
/**
* Create a new event instance.
*/
public function __construct(
public User $user,
) {}
/**
* Get the channels the event should broadcast on.
*
* @return array<int, \Illuminate\Broadcasting\Channel>
*/
public function broadcastOn(): array
{
return [
new Channel('user.events'),
];
}
/**
* Get the data to broadcast.
*
* @return array<string, mixed>
*/
public function broadcastWith(): array
{
return [
'userId' => $this->user->id,
'name' => $this->user->name,
'email' => $this->user->email,
];
}
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.