不能在 Laravel blade 模板中使用类型为 stdClass 的 object 作为数组
Cannot use object of type stdClass as array in Laravel blade template
我正在从控制器的 Laravel blade 模板中传递一个数组。但是显示错误
Cannot use object of type stdClass as array
这是我传递给视图的数组
[[{"id":10,"user_id":4,"service_speciality":"4","contact":"789","created_at":"2018-06-06 05:52:22","updated_at":"2018-06-06 05:52:22","branch_id":3,"name":"lene","doctor_email":"lene@gmail.com","service_name":"Tooth pain"}],[{"id":8,"user_id":4,"service_speciality":"1","contact":"123","created_at":"2018-06-06 05:51:41","updated_at":"2018-06-06 05:51:41","branch_id":1,"name":"lene","doctor_email":"lene@gmail.com","service_name":"Kneck pain"}]]
这是我的 blade 模板视图,我在那里出错了
@foreach($doctor as $datum)
<div id="pg-112-0" class="panel-grid panel-no-style col-lg-12">
@foreach($datum as $data)
<div id="pgc-112-0-0" class="panel-grid-cell col-lg-4">
<div id="panel-112-0-0-0" class="so-panel widget widget_pw_person_profile widget-person-profile panel-first-child panel-last-child" data-index="0">
<div class="person-profile h-card">
<div class="person-profile__container">
<div class="person-profile__basic-info">
<h4 class="person-profile__name p-name">
<a href="{{ url('/doctor/'.str_slug($data["name"], "-").'-'.$data["id"] ) }}">
Dr. {{ $data['name'] }}
</a>
</h4>
<div class="person-profile__label">
{{ $data['service_name'] }} Specialist
</div>
</div>
<a class="btn btn-secondary btn-block person-profile__button" href="{{ url('/doctor/'.str_slug($data["name"], "-").'-'.$data["id"] ) }}" target="_self">Read More</a>
</div>
</div>
</div>
</div>
@endforeach
</div>
@endforeach
错误消息说明了一切。更改您的代码:
$data['SOMETHING']
到
$data->SOMETHING
示例从:$data['service_name']
到 $data->service_name
我正在从控制器的 Laravel blade 模板中传递一个数组。但是显示错误
Cannot use object of type stdClass as array
这是我传递给视图的数组
[[{"id":10,"user_id":4,"service_speciality":"4","contact":"789","created_at":"2018-06-06 05:52:22","updated_at":"2018-06-06 05:52:22","branch_id":3,"name":"lene","doctor_email":"lene@gmail.com","service_name":"Tooth pain"}],[{"id":8,"user_id":4,"service_speciality":"1","contact":"123","created_at":"2018-06-06 05:51:41","updated_at":"2018-06-06 05:51:41","branch_id":1,"name":"lene","doctor_email":"lene@gmail.com","service_name":"Kneck pain"}]]
这是我的 blade 模板视图,我在那里出错了
@foreach($doctor as $datum)
<div id="pg-112-0" class="panel-grid panel-no-style col-lg-12">
@foreach($datum as $data)
<div id="pgc-112-0-0" class="panel-grid-cell col-lg-4">
<div id="panel-112-0-0-0" class="so-panel widget widget_pw_person_profile widget-person-profile panel-first-child panel-last-child" data-index="0">
<div class="person-profile h-card">
<div class="person-profile__container">
<div class="person-profile__basic-info">
<h4 class="person-profile__name p-name">
<a href="{{ url('/doctor/'.str_slug($data["name"], "-").'-'.$data["id"] ) }}">
Dr. {{ $data['name'] }}
</a>
</h4>
<div class="person-profile__label">
{{ $data['service_name'] }} Specialist
</div>
</div>
<a class="btn btn-secondary btn-block person-profile__button" href="{{ url('/doctor/'.str_slug($data["name"], "-").'-'.$data["id"] ) }}" target="_self">Read More</a>
</div>
</div>
</div>
</div>
@endforeach
</div>
@endforeach
错误消息说明了一切。更改您的代码:
$data['SOMETHING']
到
$data->SOMETHING
示例从:$data['service_name']
到 $data->service_name