PHP code example of nikapps / ortc-laravel

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

    

nikapps / ortc-laravel example snippets


php artisan make:event TestEvent


namespace App\Events;

use App\Events\Event;
use Illuminate\Queue\SerializesModels;
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;

/**
 * Add implements ShouldBroadcast to EventClass
 */
class TestEvent extends Event implements ShouldBroadcast
{
    use SerializesModels;

    /**
     * All public variables will be automatically added to the broadcast payload.
     */
    public $value;
    
    private $userId;

    /**
     * Create a new event instance.
     *
     * @param User $user
     * @param $value
     * @return void
     */
    public function __construct(User $user, $value)
    {
        $this->userId = $user->id;
        $this->value = $value;
    }

    /**
     * Get the channels the event should be broadcast on.
     *
     * @return array
     */
    public function broadcastOn()
    {
        return ['userId_' . $userId];
    }
    
    /**
     * Get the broadcast event name.
     *
     * @return mixed also could be an array
     */
    public function broadcastAs()
    {
        return 'testEvent';
    }