PHP code example of 7amoood / laravel-appsync-broadcaster

1. Go to this page and download the library: Download 7amoood/laravel-appsync-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/ */

    

7amoood / laravel-appsync-broadcaster example snippets


class OrderUpdated implements ShouldBroadcast
{
    use Dispatchable, InteractsWithSockets, SerializesModels;

    public $order;

    public function __construct(Order $order)
    {
        $this->order = $order;
    }

    public function broadcastOn()
    {
        return new PrivateChannel('orders/' . $this->order->id);
    }
}

event(new OrderUpdated($order));

public function broadcastOn()
{
    return new PresenceChannel('chat/room/' . $this->roomId);
}

// Private channel authorization
Broadcast::channel('orders/{orderID}', function ($user, $orderID) {
    return (int) $user->id === (int) Order::find($orderID)->user_id;
});

// Presence channel authorization
Broadcast::channel('chat/room/{roomId}', function ($user, $roomId) {
    if ($user->canAccessRoom($roomId)) {
        return ['id' => $user->id, 'name' => $user->name];
    }
});
bash
php artisan vendor:publish --tag=appsync-config
bash
php artisan appsync:worker
bash
php artisan appsync:worker --transport=websocket
php artisan appsync:worker --batch-size=100 --flush-interval=200
php artisan appsync:worker --redis-channel=appsync:events --stats-interval=30