Laravel Blade:在 object 中调用 属性 结果为 NULL

Laravel Blade: calling property in object results in NULL

我正在使用 blade 显示包裹。该包包含一些真或假的选项。但是,当我尝试使用 blade 访问这些选项时,它 returns NULL。这是完整的 JSON object $item:

{"id":1,"name":"Budget Pakket","created_at":"2018-03-05 20:38:36","updated_at":"2018-03-05 20:38:36","script_options":[{"id":1,"name":"CMS","price":506,"parent_id":null,"type_id":3,"created_at":"2018-03-05 20:38:36","updated_at":"2018-03-05 20:38:36","pivot":{"package_id":1,"script_option_id":1,"included":1}},{"id":2,"name":"Foto Album","price":481,"parent_id":null,"type_id":2,"created_at":"2018-03-05 20:38:36","updated_at":"2018-03-05 20:38:36","pivot":{"package_id":1,"script_option_id":2,"included":1}},{"id":3,"name":"Parallax Images","price":643,"parent_id":null,"type_id":1,"created_at":"2018-03-05 20:38:36","updated_at":"2018-03-05 20:38:36","pivot":{"package_id":1,"script_option_id":3,"included":1}},{"id":4,"name":"Meerdere Menus","price":868,"parent_id":null,"type_id":3,"created_at":"2018-03-05 20:38:36","updated_at":"2018-03-05 20:38:36","pivot":{"package_id":1,"script_option_id":4,"included":1}},{"id":5,"name":"Logo Design","price":370,"parent_id":null,"type_id":1,"created_at":"2018-03-05 20:38:36","updated_at":"2018-03-05 20:38:36","pivot":{"package_id":1,"script_option_id":5,"included":0}},{"id":6,"name":"Deadline","price":179,"parent_id":null,"type_id":2,"created_at":"2018-03-05 20:38:36","updated_at":"2018-03-05 20:38:36","pivot":{"package_id":1,"script_option_id":6,"included":0}},{"id":7,"name":"Thema Op Maat","price":146,"parent_id":null,"type_id":3,"created_at":"2018-03-05 20:38:36","updated_at":"2018-03-05 20:38:36","pivot":{"package_id":1,"script_option_id":7,"included":0}},{"id":8,"name":"Thema Kant-en-Klaar","price":390,"parent_id":null,"type_id":1,"created_at":"2018-03-05 20:38:36","updated_at":"2018-03-05 20:38:36","pivot":{"package_id":1,"script_option_id":8,"included":1}},{"id":9,"name":"Bulk Email","price":311,"parent_id":null,"type_id":1,"created_at":"2018-03-05 20:38:36","updated_at":"2018-03-05 20:38:36","pivot":{"package_id":1,"script_option_id":9,"included":0}},{"id":10,"name":"Layouts","price":497,"parent_id":null,"type_id":1,"created_at":"2018-03-05 20:38:36","updated_at":"2018-03-05 20:38:36","pivot":{"package_id":1,"script_option_id":10,"included":1}}]}

因此,据我所知,这应该可以显示 script_options:

{{ $item->script_options }}

我还尝试使用这些代码行遍历它们:

@foreach($item->script_options as $option)
    <tr>
        {{ $option }}
    </tr>
@endforeach

但由于某种原因它返回 NULL....

编辑

我用

检索了结果
$result = Package::with('scriptOptions')->get();
return view('package.index', compact('result'));

然后我用这个遍历了 3 个结果:

@foreach($result as $item)
    ......
@endforeach

编辑 2

尝试 {{ dd($result) }} 在您的 blade 文件上查看 $result 中是否有数据。