0

当用户向他的所有朋友创建帖子时,我正在尝试广播该事件。Laravel Echo 没有监听这些事件。Pusher我可以在网站上看到日志。所以事件被发送到推送者。

这是我的时间线代码:

<template>
<div>
    <div class="row">
        <status-box :authUser="authUser"></status-box>
    </div>

    <div class="row">
        <div class="col-lg-8">
            <div v-if="statuses.length">
                <status v-for="status in statuses" :status="status"></status>
            </div>
            <div v-else>
                <p>No posts to show yet.</p>
            </div>
        </div>
    </div>
</div>

<script>
import EventHub from './../eventhub.js';

export default {

    data() {
        return {
            statuses: [],
            authUser: null,
        };
    },

    methods: {
        pushNewStatus(status) {
            status.parent_id = null;
            this.statuses.unshift(status);

            // Broadcasting the event to so that user's friends can see the post in realtime
            Echo.private('status.' + status.id)
                .listen('StatusWasPosted', (e) => {
                    this.pushNewStatus(e.status);
                });
        }
    },

    mounted() {
        EventHub.$on('status-posted', this.pushNewStatus)

        axios.get('/chatty/getStatuses/')
            .then(({data}) => {
                this.statuses = data.statuses;
                this.authUser = data.user_name;
            })
            .catch(error => console.log(error));
    }

}

这是频道授权逻辑:

Broadcast::channel('status.{statusId}', function ($user, $statusId) {
$status = Status::find($statusId);
$status_owner = User::find($status->user_id);
return $user->isFriendsWith($status_owner);

});

StatusWasPosted这是事件类中的频道名称

public function broadcastOn() {
    return new PrivateChannel('status.' . $this->status->id);

}

status-posted创建新状态时,我在状态组件中发出。

我哪里错了??

4

0 回答 0