如何广播可以为每个用户专门定制的 laravel 事件

How to broadcast a laravel event that can be specifically customized for each user

我在每个用户屏幕上都有一个待售随机产品网格。当另一个用户购买产品时,如果该产品在其他用户屏幕上可见,我需要它淡出并加载新产品。鉴于产品网格是随机排序的,我如何向每个用户广播一个对他们来说是独一无二的新产品(即不会复制已经在他们的屏幕上出售的产品)。我还在使用 Laravel 5.2。以前的开发者没有升级他们的版本,我现在无法更改。

这是 ajax 函数,当用户购买产品并在屏幕上加载新产品时。

 $(document).ready(function(){
            $.ajaxSetup({
                headers: {
                    'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
                }
            });
            $('form.buy-product-form').on('submit', (function (e) {
                e.preventDefault();
                var product_id = $(this).closest('.product').attr("id"); //new
                var element = $(this).closest('.product');
                $.ajax({
                    url: $(this).attr('action'),
                    type: 'POST',
                    data: {'id': product_id, 'all_ids': getProductsShown()},
                    dataType: 'json',
                    success: function (data) {
                        if(data.valid_funds) {
                            $(element).css('background-color', 'red');
                            $(element).fadeOut("1000", function () {
                                $(element).fadeIn("1000", function () {
                                    $(element).animate({backgroundColor: 'green', color: 'white'}, 1000);
                                    $(element).attr("id", data.id);
                                    $(element).find("#price").html(data.price);
                                    $(element).find("#quantity").html(data.quantity);
                                    $(element).find("#seller").html(data.seller);
                                    $(element).find("#total-price").html(data.price * data.quantity);
                                    $(element).find('form').attr("action", "/UoE/buy-product/" + data.id);
                                    $(element).css('background-color', 'white');
                                });
                            });

                            updatePlayerCapital(data.player_capital, data.total_price);
                            updatePlayerUtility(data.player_utility, data.marginal_utility);
                            updatePlayerPurchases(data.purchases);

                        }else if(data.void) {
                            $(element).css('background-color', 'red');
                            $(element).fadeOut("1000", function(){
                                $(element.remove());
                            });

                            updatePlayerCapital(data.player_capital, data.total_price);
                            updatePlayerUtility(data.player_utility, data.marginal_utility);
                            updatePlayerPurchases(data.purchases);

                        }else {
                            window.alert("You do not have enough funds!");
                        }
                    },
                    error: function () {
                            window.alert("Error, product may no longer exist");
                    }
                });
            }));
        });

嗯,我不能从你的代码中完全看出,但如果你有用户 ID 或用户名之类的东西,你能为每个 UUID 创建一个频道,然后每当你需要 'custom'事件已发送;只是在那个私人频道上发送吗?