如果我测试它只是为了测试,Pusher 就可以工作,但是当我激活它以添加新的考试时,它就不起作用了。
我做活动课ExamAddedEvent implements ShouldBroadcast。
和这段代码。
public function broadcastOn()
{
return ['notifications-channel'];
}
public function broadcastAs()
{
return 'exam-added';
}
我的布局:
<script src="https://js.pusher.com/7.0/pusher.min.js"></script>
<script>
// Enable pusher logging - don't include this in production
Pusher.logToConsole = true;
var pusher = new Pusher('99257b25d6fbd6f11efc', {
cluster: 'eu'
});
var channel = pusher.subscribe('notifications-channel');
channel.bind('exam-added', function(data) {
alert(JSON.stringify(data));
toastr.success('New Exam Added!')
});
</script>
toastr msdn 我在布局中使用 css 和 js,如果我移动( toastr.success('New Exam Added!') )到另一个,它可以工作<script>。当我重新加载页面时它有效,但当我添加新考试时它不起作用
这是我的Examcontroller
$exam->update([
'active' => 1,
]);
// هنا هنفعل البوشر عن طريق ميسود الايفنت واسم الايفنت اللى انشاناه
event(new ExamAddedEvent);
return redirect( url("dashboard/exams") );
}
为什么它不起作用?
.env 一切正常,复制过去,无需更改。