刀片模板中的 laravel 致命错误异常


laravel FatalErrorException in the blade template

我将变量response从我的控制器发送到我的视图。

所以在我看来,如果我这样做:

{{response}}

我可以看到响应,所以它就在那里。

但是response是一个 JSON 格式字符串,所以我需要解析它,

我想在刀片中执行此操作。

我试过这个

<!DOCTYPE html>
<html>
<head>
<title>Master Response</title>
</head>
<body>
{{
        $json_a = json_decode($response, true);
        $hits = $json_a['hits']['hits'];
}}
</body>
</html>

但是我得到了这个错误

Whoops, looks like something went wrong.
1/1
FatalErrorException in 95df32e49f76c09bb366fa2eba52e460d30085dd.php line 7:
parse error
in 95df32e49f76c09bb366fa2eba52e460d30085dd.php line 7

刀片系统使用{{ $var }}来回显数据。如果要在刀片中用 PHP 执行操作,则需要使用 PHP 标记,如下所示:

<!DOCTYPE html>
<html>
<head>
    <title>Master Response</title>
</head>
<body>
<?php
        $json_a = json_decode($response, true);
        $hits = $json_a['hits']['hits'];
?>
</body>
</html>