composer require pusher/pusher-php-server
Register Account at: https://dashboard.pusher.com
app_id = "1692174"
key = "795c59c519a8cccf8ee8"
secret = "84a42c296ebcea8cdf52"
cluster = "ap1"
<script src="https://js.pusher.com/7.0/pusher.min.js"></script>
php artisan make:event NotificationEvent
class NotificationEvent implements ShouldBroadcast{
use Dispatchable, InteractsWithSockets, SerializesModels;
public $message;
function __construct(Request $request){
$this->message = $request->contents;
}
function broadcastOn(){
return ['notification'];
}
}
//Thay giá trị PUSHER_APP_KEY vào chỗ xxx này nhé
var pusher = new Pusher('795c59c519a8cccf8ee8', {
encrypted: true,
cluster: "ap1"
});
var channel = pusher.subscribe('notification');
channel.bind('App\\Events\\NotificationEvent', function(d){
console.log(d);
});
function notification(Request $request) {
event(new App\Events\NotificationEvent($request));
//return redirect('getPusher');
});