Skip to content

Instantly share code, notes, and snippets.

@Maras0830
Last active June 28, 2016 07:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Maras0830/d1c110f0bd297a91f0537a6ebf1b0e96 to your computer and use it in GitHub Desktop.
Save Maras0830/d1c110f0bd297a91f0537a6ebf1b0e96 to your computer and use it in GitHub Desktop.
app\Events\SendMessage.php
<?php
namespace App\Events;
use App\User;
use Illuminate\Queue\SerializesModels;
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
class SendMessage extends Event implements ShouldBroadcast
{
use SerializesModels;
private $user;
private $message;
/**
* Create a new event instance.
*
* @return void
*/
public function __construct(Array $user, $message = '')
{
$this->user = $user;
$this->message = $message;
}
/**
* Payload
*
* @return array
*/
public function broadcastWith()
{
return [
'id' => $this->user['id'],
'username' => $this->user['username'],
'message' => $this->message,
];
}
/**
* Get the channels the event should be broadcast on.
*
* @return array
*/
public function broadcastOn()
{
return ['laravel-tutorial-event-channel-'.$this->user['id']];
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment