Skip to content

Instantly share code, notes, and snippets.

@Maras0830
Created June 28, 2016 07:46
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/f781739d7b82534857a7d46dc9109f42 to your computer and use it in GitHub Desktop.
Save Maras0830/f781739d7b82534857a7d46dc9109f42 to your computer and use it in GitHub Desktop.
views/push.blade.php
<!DOCTYPE html>
<html>
<head>
<title>Laravel</title>
<script src="/bower_components/jquery/dist/jquery.js"></script>
<script src="https://js.pusher.com/3.1/pusher.min.js"></script>
<style>
#message {
height:300px;
width:30%
background-color: #cccccc;
}
</style>
</head>
<body>
<div class="container">
<div class="row">
<div class="col-md-6 col-md-offset-3">
<h1>Laravel Event Broadcasting Demo</h1>
<!-- 訊息列表 -->
<div id="message">
</div>
</div>
</div>
</div>
</body>
<script>
// Enable pusher logging - don't include this in production
Pusher.logToConsole = true;
var pusher = new Pusher('{{env('PUSHER_KEY','')}}', {
cluster: 'ap1',
encrypted: true
});
var channel = pusher.subscribe('laravel-tutorial-event-channel-{{$member_id}}');
channel.bind('App\\Events\\SendMessage', function(data) {
$('#message').append('<p>'+data.username + ': '+ data.message + '</p>');
});
</script>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment