<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
homedoctor-es / laravel-eventbridge-broadcaster example snippets
'connections' => [
'eventbridge' => [ //The connection name will be used as default eventbus
'driver' => 'eventbridge',
'region' => env('AWS_DEFAULT_REGION'),
'key' => env('AWS_ACCESS_KEY_ID'),
'endpoint' => env('AWS_URL'),
'secret' => env('AWS_SECRET_ACCESS_KEY'),
'source' => env('AWS_EVENTBRIDGE_SOURCE'),
],
// ...
],
BROADCAST_DRIVER=eventbridge
use App\Models\Order;
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
use Illuminate\Broadcasting\InteractsWithBroadcasting;
use Illuminate\Queue\SerializesModels;
class OrderShipped implements ShouldBroadcast
{
use SerializesModels;
/**
* The order that was shipped.
*
* @var \App\Models\Order
*/
public $order;
/**
* Create a new event instance.
*
* @param \App\Models\Order $order
* @return void
*/
public function __construct(Order $order)
{
$this->order = $order;
$this->broadcastVia('eventbridge');
}
/**
* Get the topics that model events should broadcast on.
*
* @return array
*/
public function broadcastOn()
{
return ['orders']; // This is the Event bus name
}
}
/**
* Get and format the data to broadcast.
*
* @return array
*/
public function broadcastWith()
{
return [
'action' => 'parcel_handled',
'data' => [
'order-id' => $this->order->id,
'order-total' => $this->order->total,
],
];
}
/**
* The event's broadcast name/subject.
*
* @return string
*/
public function broadcastAs()
{
return "orders.{$this->action}";
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.