Чтобы выполнить настройку такого типа, вы можете использовать Pusher или любого другого аналогичного провайдера. После регистрации в pusher вы можете бесплатно отправлять 200 тыс. Уведомлений в день, вы можете проверить ограничения после входа в систему в pusher.Прежде чем мы продолжим, пожалуйста, установите официальный php-пакет pusher
composer require pusher/pusher-php-server
. Из панели инструментов pusher получите app_id
, key
, secret
и cluster
теперь в вашем контроллере / модели, куда вы вставляете данные.в базу данных добавьте следующий код
//You will get cluster name from pusher.com replace it below
$options = ['cluster' => 'mt1', 'encrypted' => true];
//Replace your key, app_id and secret in the following lines
$pusher = new Pusher(
'key',
'secret',
'app_id',
$options
);
//this could be a single line of message or a json encoded array, in your case you want to pass some data to display in table I assume you have an array
$message= json_encode(['name' => 'John doe', 'age' => 42, 'etc' => 'etc']);
//Send a message to users channel with an event name of users-list. Please mind this channel name and event name could be anything but it should match that with your view
$pusher->trigger('users', 'users-list', $message);
Теперь перед вашим тегом </body>
вставьте следующий код
<!-- Incldue Pusher Js -->
<script src="https://js.pusher.com/4.2/pusher.min.js"></script>
<script>
//Remember to replace key and cluster with the credentials that you have got from pusher.
var pusher = new Pusher('key', {
cluster: 'mt1',
encrypted: true
});
//In case you have decided to use a different channel and event name in your controller then change it here to match with the one that you have used
var channel = pusher.subscribe('users');
channel.bind('users-list', function(message) {
//if you will console.log(message) at this point you will see the data
//that was sent from your controller is available here please consume as you may like
alert(message);
});
</script>