在来自控制器的 javascript 通知函数中显示数据 (Laravel)

Display data in javascrip Notification function from Controller (Laravel)

我将通知功能与 javascript 一起使用,我想在通知中显示来自 Controller 的数据

这是我的 javascript 错误 return

function notifyMe() {

           function AutoRefresh( t ) {
               setTimeout("location.reload(true);", t);
            }
        // Let's check if the browser supports notifications
        if (!("Notification" in window)) {
            alert("This browser does not support desktop notification");
        }

        // Let's check whether notification permissions have already been granted
        else if (Notification.permission === "granted") {

            var notification = new Notification({{ $postnotif->title }});
        }

        else if (Notification.permission !== "denied") {
            Notification.requestPermission().then(function (permission) {
            if (permission === "granted") {
            var notification = new Notification({{ $postnotif->title }});
            }
            });
        }

        }
       </script>

它 return 这个错误 error return

这是我在控制器中的逻辑

$postnotif = DB::table('post_contents')->where('created_at', '=', '2019-03-11 20:07:49')->first();

这是来自 $postnotif

的 json
{#1287
  +"id": 1
  +"post_id": 1
  +"lang": "id"
  +"slug": "beranda"
  +"title": "Beranda"
  +"body": "<p>Website Resmi FIFGROUP, member of ASTRA Perusahaan Pembiayaan Terpercaya di Indonesia.</p>"
  +"excerpt": null
  +"image": null
  +"tag": "astra, pembiayaan, terpercaya, indonesia, cicilan, kredit, pembiayaan motor bekas, pembiayaan motor baru, pembiayaan multiguna, pembiayaan umrah, dana kuliah, m "
  +"metas": "a:1:{s:4:"file";N;}"
  +"created_at": "2019-03-11 20:07:49"
  +"updated_at": "2019-08-30 00:40:47"
}

如何从控制器正确声明到javascript?

您必须按以下方式访问 laravel 变量:

     var notification = new Notification({!! $postnotif->title !!});