如果数据库更改,发送通知



如果任何数据已插入到数据库中,我要向另一个页面发出警报消息。我该怎么做呢?

这是控制器页面:

public function insertFunction(Request $request) {
$insert = New ExampleTable;
$insert->test_id = $request->id;
$insert->save();
// after this i want to send notification to the another page(panel.blade.php) without refreshing
}

这是我想看到通知的panel.blade.php:

<script> 
// if notification comes, do it
alert("notification came");
</script>

我正在使用mysql。如果你能帮助我,我会很高兴的,谢谢。

假设你想要实时通知,最好的做法是使用Laravel的广播功能。

最有可能的是,你最终会使用push之类的东西。

但是,您可以创建一个自定义的java-脚本循环,该循环不断地询问端点是否有任何更新,但这将是糟糕的实践,不建议使用

。这是一篇我觉得很有帮助的文章。好运!

最新更新