Last active
June 21, 2021 03:22
-
-
Save ptcampbell/4f9dad9ebd539e0357e279ee75663ee8 to your computer and use it in GitHub Desktop.
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
declare global { | |
interface Window { | |
Pusher: any | |
} | |
} | |
import Echo from 'laravel-echo' | |
window.Pusher = require('pusher-js') | |
window.Echo = new Echo({ | |
broadcaster: 'pusher', | |
key: 'ad6bcb7780f189a3746e', | |
cluster: 'us3', | |
forceTLS: true, | |
}) | |
const channel = window.Echo.channel('toast-channel') | |
channel.listen('.toast-event', function(data) { | |
alert(JSON.stringify(data)) | |
}) |
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 Illuminate\Broadcasting\Channel; | |
use Illuminate\Broadcasting\InteractsWithSockets; | |
use Illuminate\Broadcasting\PresenceChannel; | |
use Illuminate\Broadcasting\PrivateChannel; | |
use Illuminate\Contracts\Broadcasting\ShouldBroadcast; | |
use Illuminate\Foundation\Events\Dispatchable; | |
use Illuminate\Queue\SerializesModels; | |
class ToastMessage implements ShouldBroadcast | |
{ | |
use Dispatchable, InteractsWithSockets, SerializesModels; | |
public $message; | |
/** | |
* Create a new event instance. | |
* | |
* @return void | |
*/ | |
public function __construct($message) | |
{ | |
$this->message = $message; | |
} | |
/** | |
* Get the channels the event should broadcast on. | |
* | |
* @return \Illuminate\Broadcasting\Channel|array | |
*/ | |
public function broadcastOn() | |
{ | |
return new Channel('toast-channel'); | |
// return new PrivateChannel('toast.' . $this->user); | |
} | |
public function broadcastAs() | |
{ | |
return 'toast-message'; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment