PHP Laravel

Laravel Pusher

Installing
composer require pusher/pusher-php-server
Configuration .env

Register Account at: https://dashboard.pusher.com

app_id = "1692174"
key = "795c59c519a8cccf8ee8"
secret = "84a42c296ebcea8cdf52"
cluster = "ap1"
Javascript
<script src="https://js.pusher.com/7.0/pusher.min.js"></script>
Create Event
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'];
    }
}
Notification receive
//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);
});
	
Push Notification
function notification(Request $request) {
    event(new App\Events\NotificationEvent($request));
    //return redirect('getPusher');
});