我的刀片中有以下foreach循环,显示错误:
试图获取非对象的属性“ pros_name”
我该如何解决?
@foreach ($reports as $report)
<tr>
<td>{{ $report->room_no }}</a></td>
<td>{{ $report->room_type }}</td>
@if($report->book_date== null || ($report->book_date != null && ($report->release_date != null && $report->release_date < date('Y-m-d'))))
<td class="text-danger"><strong>Vacant</strong></td>
<td>{{ $report->price }}</td>
<td>---</td>
<td></td>
@endif
@if($report->book_date != null && ( $report->release_date ==null || $report->release_date >= date('Y-m-d')))
@php
$doc = DB::table('gen_resident_room')
->Join('sales_pipeline', 'gen_resident_room.person_id', '=', 'sales_pipeline.id')
->where([['room_id',$report->room_id]])->first();
$n = explode (",",$doc->pros_name); //error
@endphp
@if($doc->stage === "MoveIn")
<td class="text-success"><b>Occupied</b></td>
@else
<td class="text-success"><b>Booked</b></td>
@endif
<td>{{ $report->price }}</td>
<td>{{ $doc->price }}</td>
<td>{{ $n[0] }} {{ $n[1] }} {{ $n[2] }}</td>
@endif
</tr>
@endforeach
答案 0 :(得分:0)
请尝试检查$ doc是否包含数据。似乎该文档为空,因此其脚本执行失败并引发错误。
您还可以验证代码,例如:
if(!empty($doc))
{
// Do you stuff
}
或
if(isset($doc->pros_name)) {
$n = explode (",",$doc->pros_name);
}