Last active
June 28, 2016 07:50
-
-
Save Maras0830/d1c110f0bd297a91f0537a6ebf1b0e96 to your computer and use it in GitHub Desktop.
app\Events\SendMessage.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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